/[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.8, Sun Jan 11 20:46:10 2009 UTC revision 1.5.2.9, Mon Jan 26 11:52:42 2009 UTC
# Line 15  function pblog_menu() { Line 15  function pblog_menu() {
15      'title' => 'Rebuild',      'title' => 'Rebuild',
16      'page callback' => 'pblog_rebuild',      'page callback' => 'pblog_rebuild',
17      'access callback' => 'user_access',      'access callback' => 'user_access',
18      'access arguments' => array('access statistics'),      'access arguments' => array('pblog edit'),
19            'page arguments' => array(1),
20      'type' => MENU_LOCAL_TASK,      'type' => MENU_LOCAL_TASK,
21      'weight' => 2,      'weight' => 2,
22      );      );
# Line 94  function pblog_view($node, $teaser = FAL Line 95  function pblog_view($node, $teaser = FAL
95    
96    
97    
98    $imgurl = pblog_get_random_image($node);    $imgurl = pblog_get_random_image($node->nid);
99     $teaser_images =   variable_get(pblog_teaser_images,'1');     $teaser_images =   variable_get(pblog_teaser_images,'1');
100     if ($teaser_images == 1) {     if ($teaser_images == 1) {
101       $rows = array(       $rows = array(
102          array(          array(
103            l(theme_image(pblog_get_random_image($node)), "node/$node->nid", array('attributes' => null, 'query' => null, 'fragment' => null, 'absolute' => TRUE, 'html' => TRUE)),            l(theme_image(pblog_get_random_image($node->nid)), "node/$node->nid", array('attributes' => null, 'query' => null, 'fragment' => null, 'absolute' => TRUE, 'html' => TRUE)),
104                   $node->teaser)                   $node->teaser)
105           );           );
106            $node->teaser = theme_table(NULL, $rows);            $node->teaser = theme_table(NULL, $rows);
107          } else {          } else {
108                  // make 2x2 table                  // make 2x2 table
109                  $cube_rows = array(                  $cube_rows = array(
110                                            array( l(theme_image(pblog_get_random_image($node, strip)), "node/$node->nid", array('attributes' => null, 'query' => null, 'fragment' => null, 'absolute' => TRUE, 'html' => TRUE)),                                            array( l(theme_image(pblog_get_random_image($node->nid, strip)), "node/$node->nid", array('attributes' => null, 'query' => null, 'fragment' => null, 'absolute' => TRUE, 'html' => TRUE)),
111                                                                     l(theme_image(pblog_get_random_image($node, strip)), "node/$node->nid", array('attributes' => null, 'query' => null, 'fragment' => null, 'absolute' => TRUE, 'html' => TRUE))),                                                                     l(theme_image(pblog_get_random_image($node->nid, strip)), "node/$node->nid", array('attributes' => null, 'query' => null, 'fragment' => null, 'absolute' => TRUE, 'html' => TRUE))),
112    
113                                                                    array( l(theme_image(pblog_get_random_image($node, strip)), "node/$node->nid", array('attributes' => null, 'query' => null, 'fragment' => null, 'absolute' => TRUE, 'html' => TRUE)),                                                                    array( l(theme_image(pblog_get_random_image($node->nid, strip)), "node/$node->nid", array('attributes' => null, 'query' => null, 'fragment' => null, 'absolute' => TRUE, 'html' => TRUE)),
114                                                                     l(theme_image(pblog_get_random_image($node, strip)), "node/$node->nid", array('attributes' => null, 'query' => null, 'fragment' => null, 'absolute' => TRUE, 'html' => TRUE)))                                                                     l(theme_image(pblog_get_random_image($node->nid, strip)), "node/$node->nid", array('attributes' => null, 'query' => null, 'fragment' => null, 'absolute' => TRUE, 'html' => TRUE)))
115                                                                  );                                                                  );
116    
117                  $rows = array(                  $rows = array(
# Line 142  function pblog_view($node, $teaser = FAL Line 143  function pblog_view($node, $teaser = FAL
143    
144  // puts random pic in a block on side  // puts random pic in a block on side
145  function pblog_block($op = "list", $delta = 0) {  function pblog_block($op = "list", $delta = 0) {
146    $file_dir = file_directory_path();  
147    global $user;      // get all the active pblog node ids
148    if ($op == "list") {      $result = db_query(db_rewrite_sql("SELECT n.nid FROM {node} n  WHERE n.type = 'pblog'  AND n.status = 1 ORDER BY n.created DESC"), $account->uid);
149      $block[0]["info"] = t("plog");     $items = array();
150      return $block;     while ($row = db_fetch_object($result)) {
151    }       $items[] = $row->nid;
152    else {     }
153      // now the fun bit  
154      $dir = "$file_dir/pblog/";          srand((float) microtime() * 10000000);
155      $dir_array = array();      $j = array_rand($items,4);
156      if (is_dir($dir)) {          //create a array with random node numbers
157        if ($dh = opendir($dir)) {          foreach($j as $rand){
158          while (($file = readdir($dh)) !== false) {                  $rand_node[] = $items[$rand];
159            if (filetype($dir . $file) == 'dir' &&                  }
160            $file != "." && $file != "..") {  
161              array_push($dir_array, "$file");}  
162            }  
163            closedir($dh);          $block_images =   variable_get(pblog_block_images,'1');
164          }  
165        }  
166        srand((float) microtime() * 10000000);     if ($block_images == 1) {
167        $i = array_rand($dir_array);          $block["content"] = l(theme_image(pblog_get_random_image($rand_node[0])), "node/".$rand_node[0], array('attributes' => null, 'query' => null, 'fragment' => null, 'absolute' => TRUE, 'html' => TRUE));
168        // get array of images, pick random  
169        $img_array = array();          } else {
170        if (is_dir($dir . $dir_array[$i])) {                  // make 2x2 table
171          if ($dh = opendir($dir . $dir_array[$i])) {                  $cube_rows = array(
172            while (($file = readdir($dh)) !== false) {                                            array( l(theme_image(pblog_get_random_image($rand_node[0], strip)), "node/$rand_node[0]", array('attributes' => null, 'query' => null, 'fragment' => null, 'absolute' => TRUE, 'html' => TRUE)),
173              if (!preg_match("/bw-mini.jpg$/", $file) && preg_match("/-mini.jpg$/", $file)) {                                                                     l(theme_image(pblog_get_random_image($rand_node[1], strip)), "node/$rand_node[1]", array('attributes' => null, 'query' => null, 'fragment' => null, 'absolute' => TRUE, 'html' => TRUE))),
174                array_push($img_array, "$dir_array[$i]"."/$file");  
175              }                                                                    array( l(theme_image(pblog_get_random_image($rand_node[2], strip)), "node/$rand_node[2]", array('attributes' => null, 'query' => null, 'fragment' => null, 'absolute' => TRUE, 'html' => TRUE)),
176            }                                                                     l(theme_image(pblog_get_random_image($rand_node[3], strip)), "node/$rand_node[3]", array('attributes' => null, 'query' => null, 'fragment' => null, 'absolute' => TRUE, 'html' => TRUE)))
177            closedir($dh);                                                                  );
178          }  
179        }            $block["content"] = theme_table(NULL, $cube_rows);
180        srand((float) microtime() * 10000000);          };
181        $j = array_rand($img_array);  
182        $block["content"] = l(theme_image("$file_dir/pblog/$img_array[$j]"), "node/$dir_array[$i]", array('attributes' => null, 'query' => null, 'fragment' => null, 'absolute' => TRUE, 'html' => TRUE));  
183        $block["subject"] = t("Random Image");        $block["subject"] = t("Random Image");
184        return $block;        return $block;
185    }    }
 }  
186    
187  function pblog_image($nid = NULL, $picture = NULL) {  function pblog_image($nid = NULL, $picture = NULL) {
188    $file_dir = file_directory_path();    $file_dir = file_directory_path();
# Line 574  $form['pblog_med_size_width'] = array( Line 574  $form['pblog_med_size_width'] = array(
574      '#required' => TRUE,      '#required' => TRUE,
575    );    );
576    
577      $form['pblog_block_images'] = array(
578        '#type' => 'textfield',
579        '#title' => t('Block Images'),
580        '#default_value' => variable_get('pblog_block_images', 1),
581        '#size' => 5,
582        '#maxlength' => 5,
583        '#description' => t("The number of images to show in the block, currently only 1 or 4."),
584        '#required' => TRUE,
585      );
586    
587    
588    return system_settings_form($form);    return system_settings_form($form);
589  }  }
590    
591  function pblog_rebuild($nid,$action){  function pblog_rebuild($node){
592          print "$nid $action";  //      print_r($nid);
593          $node = node_load($nid);  //      $node = node_load($nid);
594          $file_dir = file_directory_path();          $file_dir = file_directory_path();
595          $node_path = $file_dir .'/pblog/'. $node->nid;          $node_path = $file_dir .'/pblog/'. $node->nid;
596          pblog_create_thumbnails($file_dir .'/pblog/'. $node->nid);  
597            if(is_dir("$node_path")){
598                    pblog_create_thumbnails($node_path);
599                    } else {
600                    drupal_set_message('Does not seem to be a directory '. $node_path, 'error');
601                    };
602          return "rebuilding $node->title";          return "rebuilding $node->title";
603          }          }
604    
# Line 602  if ($handle = opendir($image_dir)) { Line 617  if ($handle = opendir($image_dir)) {
617          if (file_exists($image_dir .'/'. $s_root .'-strip.jpg')) {          if (file_exists($image_dir .'/'. $s_root .'-strip.jpg')) {
618            drupal_set_message('Creating strip '. $s_root, 'status');            drupal_set_message('Creating strip '. $s_root, 'status');
619          } else {          } else {
620            drupal_set_message('Unable to creating thumbnail '. $s_root, 'error');            drupal_set_message('Unable to creating strip '. $s_root, 'error');
621          }          }
622    
623          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'));          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'));
# Line 624  if ($handle = opendir($image_dir)) { Line 639  if ($handle = opendir($image_dir)) {
639    }     else  drupal_set_message("Cannot open the directory $image_dir to create thumbnails".'error');    }     else  drupal_set_message("Cannot open the directory $image_dir to create thumbnails".'error');
640  }  }
641    
642  function pblog_get_random_image($node, $size = "mini"){  function pblog_get_random_image($node_id, $size = "mini"){
643    $file_dir = file_directory_path();    $file_dir = file_directory_path();
644    $img_array = array();    $img_array = array();
645    $imgmed_array = array();    $imgmed_array = array();
646    
647    if (is_dir($file_dir .'/pblog/'. $node->nid)) {    if (is_dir($file_dir .'/pblog/'. $node_id)) {
648      if ($dh = opendir($file_dir .'/pblog/'. $node->nid)) {      if ($dh = opendir($file_dir .'/pblog/'. $node_id)) {
649        while (($file = readdir($dh)) !== false) {        while (($file = readdir($dh)) !== false) {
650          if (preg_match("/-mini.jpg$/", $file) && !preg_match("/bw-mini.jpg$/", $file) ) {          if (preg_match("/-mini.jpg$/", $file) && !preg_match("/bw-mini.jpg$/", $file) ) {
651            array_push($img_array, "$dir_array[$i]"."/$file");            array_push($img_array, "$dir_array[$i]"."/$file");
# Line 638  function pblog_get_random_image($node, $ Line 653  function pblog_get_random_image($node, $
653        }        }
654        closedir($dh);        closedir($dh);
655      }      }
656    }    }
657    
658    srand((float) microtime() * 10000000);    srand((float) microtime() * 10000000);
659    $j = array_rand($img_array);    $j = array_rand($img_array);
660    
661    if ($size == "strip"){    if ($size == "strip"){
662               return  strtr($file_dir .'/pblog/'. $node->nid . $img_array[$j],array("mini.jpg" => "strip.jpg"));               return  strtr($file_dir .'/pblog/'. $node_id . $img_array[$j],array("mini.jpg" => "strip.jpg"));
663          } else {  return($file_dir .'/pblog/'. $node->nid . $img_array[$j]); }          } else {  return($file_dir .'/pblog/'. $node_id . $img_array[$j]); }
664  }  }
665    
666    

Legend:
Removed from v.1.5.2.8  
changed lines
  Added in v.1.5.2.9

  ViewVC Help
Powered by ViewVC 1.1.2