/[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.6, Sun Sep 14 15:13:04 2008 UTC revision 1.5.2.7, Sun Nov 30 20:08:27 2008 UTC
# Line 8  Line 8 
8  * @drupal_package pblog  * @drupal_package pblog
9  *  *
10  */  */
11    /*
12    $items['pblog/rebuild/%'] = array(
13        'title' => 'Rebuild',
14        'page callback' => 'pblog_rebuild',
15        'page arguments' => array(1,2),
16        'access arguments' => array('access pblog'),
17        'type' => MENU_LOCAL_TASK,
18            'weight' => 2,
19      );    */
20    
21  function pblog_menu() {  function pblog_menu() {
22    
23      $items['node/%node/rebuild'] = array(
24        'title' => 'Rebuild',
25        'page callback' => 'pblog_rebuild',
26        'access callback' => 'user_access',
27        'access arguments' => array('access statistics'),
28        'type' => MENU_LOCAL_TASK,
29        'weight' => 2,
30        );
31    
32    
33    
34  $items['pblog/%/%'] = array(  $items['pblog/%/%'] = array(
35      'title' => 'Pblog',      'title' => 'Pblog',
36      'page callback' => 'pblog_image',      'page callback' => 'pblog_image',
37      'page arguments' => array(1, 2),      'page arguments' => array(1, 2),
38      'access arguments' => array('access pblog'),      'access arguments' => array('access pblog'),
39      'type' => MENU_CALLBACK,      'type' => MENU_CALLBACK,
40    
41    );    );
42    
43   $items['admin/settings/pblog'] = array(   $items['admin/settings/pblog'] = array(
# Line 27  $items['pblog/%/%'] = array( Line 48  $items['pblog/%/%'] = array(
48      'access arguments' => array('access administration pages'),      'access arguments' => array('access administration pages'),
49      'type' => MENU_NORMAL_ITEM,      'type' => MENU_NORMAL_ITEM,
50     );     );
51    
52    
53    
54    
55    
56    
57    return $items;    return $items;
# Line 95  function pblog_view($node, $teaser = FAL Line 120  function pblog_view($node, $teaser = FAL
120    $node->teaser = theme_table($header, $rows);    $node->teaser = theme_table($header, $rows);
121    
122    $node->body =  $node->body .'<p>';    $node->body =  $node->body .'<p>';
123      $row_count = 0;
124    sort($img_array);    sort($img_array);
125    $numberofpics = count($img_array);    $numberofpics = count($img_array);
126     for( $counter=0; $counter < $numberofpics; $counter++ ) {     for( $counter=0; $counter < $numberofpics; $counter++ ) {
127      $trans = array("mini.jpg" => "med.jpg");      $trans = array("mini.jpg" => "med.jpg");
128      $med_image = strtr($img_array[$counter], $trans);      $med_image = strtr($img_array[$counter], $trans);
129      $image_tag = theme_image("$file_dir/pblog/$node->nid$img_array[$counter]");      $image_tag = theme_image("$file_dir/pblog/$node->nid$img_array[$counter]");
130      $node->body .= l($image_tag, "pblog/$node->nid$med_image", array('attributes' => null, 'query' => null, 'fragment' => null, 'absolute' => TRUE, 'html' => TRUE));          $row[$row_count][] = l($image_tag, "pblog/$node->nid$med_image", array('attributes' => null, 'query' => null, 'fragment' => null, 'absolute' => TRUE, 'html' => TRUE));
131      $int = $counter + 1;              $int = $counter + 1;
132      if ( $int % 4 == 0 ) {      if ( $int %  variable_get(pblog_table_width,'4') == 0 ) {
133        $node->body .= '<br>';          $row_count++;
134      }      }
135    }    }
136      $node->body .= theme_table(null,$row);
137    $node = node_prepare($node, "$teaser");    return node_prepare($node,$teaser);
138    return $node;  
139  }  }
140    
141  // puts random pic in a block on side  // puts random pic in a block on side
# Line 364  function pblog_update($node){ Line 390  function pblog_update($node){
390        break;        break;
391    }    }
392    // make thumbnails of all files in the dir.    // make thumbnails of all files in the dir.
393    if ($handle = opendir($image_dir)) {  pblog_create_thumbnails($image_dir);
     while (false !== ($file = readdir($handle))) {  
       if ($file != '.' && $file != '..' && !preg_match("/-mini.jpg$/", $file)  
         && !preg_match("/-med.jpg$/", $file)) {  
         // do a little cleaning  
         $s = escapeshellcmd($file);  
         $s_root = substr($s, 0, -4);  
         // normal thumbnail  
         /* old school using system calls  
         $command = 'convert -size 120x120 "'. $image_dir .'/'. $s .'" -resize 120x120  +profile "*" "'. $image_dir .'/'. $s_root .'-mini.jpg"';  
         exec($command);  
         // black and white thumbnail cos its arty  
         $command2 = 'convert -size 120x120 "'. $image_dir .'/'. $s .'" -resize 120x120  +profile "*" -colorspace gray "'. $image_dir .'/'. $s_root .'-bw-mini.jpg"';  
         exec($command2);  
         // medium size for dialup losers  
         $command3 = 'convert -size 500x375 "'. $image_dir .'/'. $s .'" -resize 500x375  +profile "*"        "'. $image_dir .'/'. $s_root .'-med.jpg"';  
         exec($command3);  
         */  
         image_scale($image_dir .'/'. $s, $image_dir .'/'. $s_root .'-strip.jpg', 90, 90);  
         if (file_exists($image_dir .'/'. $s_root .'-strip.jpg')) {  
           drupal_set_message('Creating strip '. $s_root, 'status');  
         } else {  
           drupal_set_message('Unable to creating thumbnail '. $s_root, 'error');  
         }  
   
         image_scale($image_dir .'/'. $s, $image_dir .'/'. $s_root .'-mini.jpg', 120, 120);  
         if (file_exists($image_dir .'/'. $s_root .'-mini.jpg')) {  
           drupal_set_message('Creating thumbnail '. $s_root, 'status');  
         } else {  
           drupal_set_message('Unable to creating thumbnail '. $s_root, 'error');  
         }  
   
         image_scale($image_dir .'/'. $s, $image_dir .'/'. $s_root .'-med.jpg', 500, 375);  
         if (file_exists($image_dir .'/'. $s_root .'-med.jpg')) {  
           drupal_set_message('Creating medium image '. $s_root, 'status');  
         } else {  
           drupal_set_message('Unable to creating medium image '. $s_root, 'error');  
         }  
       }  
     }  
   }  
394  }  }
395    
396  /*  /*
# Line 483  function pblog_insert($node) { Line 469  function pblog_insert($node) {
469        break;        break;
470    }    }
471    // make thumbnails of all files in the dir.    // make thumbnails of all files in the dir.
472    if ($handle = opendir($image_dir)) {    pblog_create_thumbnails($image_dir);
473    }
474    
475    function pblog_delete(&$node) {
476      if ($node->nid != '') {
477        system("rm -r pblog/$node->nid"); }
478      else {
479        drupal_set_message('not a valid node id', 'error');
480      }
481    }
482    
483    function pblog_admin() {
484    
485      $form['pblog_stripsize'] = array(
486        '#type' => 'textfield',
487        '#title' => t('Number of images in strip'),
488        '#default_value' => variable_get('pblog_stripsize', 5),
489        '#size' => 2,
490        '#maxlength' => 2,
491        '#description' => t("Number of images to use in the strip on the bottom of the image windows. 0 disables the strip. If you dont use a odd number it will be increased by 1 to create a odd number."),
492        '#required' => TRUE,
493      );
494    
495    $form['pblog_med_size_height'] = array(
496        '#type' => 'textfield',
497        '#title' => t('Height of Medium Size Image'),
498        '#default_value' => variable_get('pblog_med_size_height', 375),
499        '#size' => 5,
500        '#maxlength' => 5,
501        '#description' => t("The height of the medium sized image that is displayed when a thumbnail is clicked on."),
502        '#required' => TRUE,
503      );
504    
505    $form['pblog_med_size_width'] = array(
506        '#type' => 'textfield',
507        '#title' => t('Width of Medium Size Image'),
508        '#default_value' => variable_get('pblog_med_size_width', 500),
509        '#size' => 5,
510        '#maxlength' => 5,
511        '#description' => t("The width of the medium sized image that is displayed when a thumbnail is clicked on."),
512        '#required' => TRUE,
513      );
514    
515      $form['pblog_thumb_size_height'] = array(
516        '#type' => 'textfield',
517        '#title' => t('Height of Thumbnail Image'),
518        '#default_value' => variable_get('pblog_thumb_size_height', 120),
519        '#size' => 5,
520        '#maxlength' => 5,
521        '#description' => t("The height of the thumbenail image that is displayed in the block and node."),
522        '#required' => TRUE,
523      );
524    
525      $form['pblog_thumb_size_width'] = array(
526        '#type' => 'textfield',
527        '#title' => t('Width of Thumbnail Image'),
528        '#default_value' => variable_get('pblog_thumb_size_width', 120),
529        '#size' => 5,
530        '#maxlength' => 5,
531        '#description' => t("The width of the thumbenail image that is displayed in the block and node."),
532        '#required' => TRUE,
533      );
534    
535     $form['pblog_strip_size_height'] = array(
536        '#type' => 'textfield',
537        '#title' => t('Height of Strip Image'),
538        '#default_value' => variable_get('pblog_strip_size_height', 90),
539        '#size' => 5,
540        '#maxlength' => 5,
541        '#description' => t("The height of the strip image that is displayed in the block and node."),
542        '#required' => TRUE,
543      );
544    
545      $form['pblog_strip_size_width'] = array(
546        '#type' => 'textfield',
547        '#title' => t('Width of Strip Image'),
548        '#default_value' => variable_get('pblog_strip_size_width', 90),
549        '#size' => 5,
550        '#maxlength' => 5,
551        '#description' => t("The width of the strip image that is displayed in the block and node."),
552        '#required' => TRUE,
553      );
554    
555      $form['pblog_table_width'] = array(
556        '#type' => 'textfield',
557        '#title' => t('Table Rows'),
558        '#default_value' => variable_get('pblog_table_width', 4),
559        '#size' => 5,
560        '#maxlength' => 5,
561        '#description' => t("The number of images to show in each row in the table of images, displayed in the node."),
562        '#required' => TRUE,
563      );
564    
565    
566      return system_settings_form($form);
567    }
568    
569    function pblog_rebuild($nid,$action){
570            print "$nid $action";
571            $node = node_load($nid);
572            $file_dir = file_directory_path();
573            $node_path = $file_dir .'/pblog/'. $node->nid;
574            pblog_create_thumbnails($file_dir .'/pblog/'. $node->nid);
575            return "rebuilding $node->title";
576            }
577    
578    function pblog_create_thumbnails($image_dir) {
579            // remove all -med -strip and -thumb first
580    
581    if ($handle = opendir($image_dir)) {
582      while (false !== ($file = readdir($handle))) {      while (false !== ($file = readdir($handle))) {
583        if ($file != '.' && $file != '..' && !preg_match("/-mini.jpg$/", $file)        if ($file != '.' && $file != '..' && !preg_match("/-mini.jpg$/", $file)
584          && !preg_match("/-med.jpg$/", $file)) {          && !preg_match("/-med.jpg$/", $file) && !preg_match("/-strip.jpg$/", $file) ) {
585          // do a little cleaning          // do a little cleaning
586          $s = escapeshellcmd($file);          $s = escapeshellcmd($file);
587          $s_root = substr($s, 0, -4);          $s_root = substr($s, 0, -4);
588          // normal thumbnail  
589          /* old school using system calls          image_scale($image_dir .'/'. $s, $image_dir .'/'. $s_root .'-strip.jpg', variable_get(pblog_strip_size_width,'90'), variable_get(pblog_strip_size_height,'90'));
         $command = 'convert -size 120x120 "'. $image_dir .'/'. $s .'" -resize 120x120  +profile "*" "'. $image_dir .'/'. $s_root .'-mini.jpg"';  
         exec($command);  
         // black and white thumbnail cos its arty  
         $command2 = 'convert -size 120x120 "'. $image_dir .'/'. $s .'" -resize 120x120  +profile "*" -colorspace gray "'. $image_dir .'/'. $s_root .'-bw-mini.jpg"';  
         exec($command2);  
         // medium size for dialup losers  
         $command3 = 'convert -size 500x375 "'. $image_dir .'/'. $s .'" -resize 500x375  +profile "*"        "'. $image_dir .'/'. $s_root .'-med.jpg"';  
         exec($command3);  
         */  
         image_scale($image_dir .'/'. $s, $image_dir .'/'. $s_root .'-strip.jpg', 90, 90);  
590          if (file_exists($image_dir .'/'. $s_root .'-strip.jpg')) {          if (file_exists($image_dir .'/'. $s_root .'-strip.jpg')) {
591            drupal_set_message('Creating strip '. $s_root, 'status');            drupal_set_message('Creating strip '. $s_root, 'status');
592          } else {          } else {
593            drupal_set_message('Unable to creating thumbnail '. $s_root, 'error');            drupal_set_message('Unable to creating thumbnail '. $s_root, 'error');
594          }          }
595    
596          image_scale($image_dir .'/'. $s, $image_dir .'/'. $s_root .'-mini.jpg', 120, 120);          image_scale($image_dir .'/'. $s, $image_dir .'/'. $s_root .'-mini.jpg', variable_get(pblog_thumb_size_width,'120'),variable_get(pblog_thumb_size_height,'120'));
597          if (file_exists($image_dir .'/'. $s_root .'-mini.jpg')) {          if (file_exists($image_dir .'/'. $s_root .'-mini.jpg')) {
598            drupal_set_message('Creating thumbnail '. $s_root, 'status');            drupal_set_message('Creating thumbnail '. $s_root, 'status');
599          } else {          } else {
600            drupal_set_message('Unable to creating thumbnail '. $s_root, 'error');            drupal_set_message('Unable to creating thumbnail '. $s_root, 'error');
601          }          }
602    
603          image_scale($image_dir .'/'. $s, $image_dir .'/'. $s_root .'-med.jpg', 500, 375);          image_scale($image_dir .'/'. $s, $image_dir .'/'. $s_root .'-med.jpg',  variable_get(pblog_med_size_width,'500'), variable_get(pblog_med_height_width,'375'));
604          if (file_exists($image_dir .'/'. $s_root .'-med.jpg')) {          if (file_exists($image_dir .'/'. $s_root .'-med.jpg')) {
605            drupal_set_message('Creating medium image '. $s_root, 'status');            drupal_set_message('Creating medium image '. $s_root, 'status');
606          } else {          } else {
# Line 523  function pblog_insert($node) { Line 608  function pblog_insert($node) {
608          }          }
609        }        }
610      }      }
611    }    }     else  drupal_set_message("Cannot open the directory $image_dir to create thumbnails".'error');
 }  
   
 function pblog_delete(&$node) {  
   if ($node->nid != '') {  
     system("rm -r pblog/$node->nid"); }  
   else {  
     drupal_set_message('not a valid node id', 'error');  
   }  
 }  
   
 function pblog_admin() {  
   
   $form['pblog_stripsize'] = array(  
     '#type' => 'textfield',  
     '#title' => t('Number of images in strip'),  
     '#default_value' => variable_get('pblog_stripsize', 5),  
     '#size' => 2,  
     '#maxlength' => 2,  
     '#description' => t("Number of images to use in the strip on the bottom of the image windows. 0 disables the strip. If you dont use a odd number it will be increased by 1 to create a odd number."),  
     '#required' => TRUE,  
   );  
   
   return system_settings_form($form);  
612  }  }

Legend:
Removed from v.1.5.2.6  
changed lines
  Added in v.1.5.2.7

  ViewVC Help
Powered by ViewVC 1.1.2