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

Diff of /contributions/modules/html_export/html_export.module

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

revision 1.2, Wed Jun 4 18:06:18 2008 UTC revision 1.3, Thu Jun 5 19:25:16 2008 UTC
# Line 66  function html_export_settings() { Line 66  function html_export_settings() {
66  * Implementation of hook_settings_submit  * Implementation of hook_settings_submit
67  */  */
68  function html_export_settings_submit($form_id, $form_values) {  function html_export_settings_submit($form_id, $form_values) {
         $root = substr($_SERVER['HTTP_REFERER'],0,strpos($_SERVER['HTTP_REFERER'],$_GET['q']));  
69          if($form_values["html_export"] == 1){          if($form_values["html_export"] == 1){
70                  //need a better way of stripping out the base URL BECAUSE if there is NO base path then this will most likely fail to grab the root correctly                  $clean = variable_get('clean_url',0);
71                  //Look for something that just returns the server url that it's located on eg http://site.com/                  //turn clean URLs off temporarily if they are on
72                  //this also might all be unnessecary as all drupal sites submit their index.php to themselves....so I might just be able to send out a call to http_referer.  Pull it out and see what it's storing.                  if($clean){
73                  $root = substr($_SERVER['HTTP_REFERER'],0,strpos($_SERVER['HTTP_REFERER'],base_path()));                          variable_set('clean_url',0);
74                    }
75                    $root = substr($_SERVER['HTTP_REFERER'],0,strpos($_SERVER['HTTP_REFERER'],$_GET['q']));
76                    //drupal_set_message($root);
77                    //remove the ?q= if clean URLs are off
78                    if(strpos($root,'?q=') != 0){
79                            $root = substr($root,0,strpos($root,'?q='));
80                    }
81                  //create a folder html_export to put the directory in                  //create a folder html_export to put the directory in
82                  $dir = file_create_path(file_directory_path() . '/html_export');                  $dir = file_create_path(file_directory_path() . '/html_export');
83                  file_check_directory($dir, 1);                  file_check_directory($dir, 1);
# Line 94  function html_export_settings_submit($fo Line 100  function html_export_settings_submit($fo
100    
101                  //grab all the nodes in the system that are published and then build out a list of url's to rename in the rendered code.                  //grab all the nodes in the system that are published and then build out a list of url's to rename in the rendered code.
102                  //similar to url rewrite and will need to take that into account eventually                  //similar to url rewrite and will need to take that into account eventually
103                  $result = db_query("SELECT nid FROM node WHERE status=1");                  $result = db_query("SELECT nid FROM {node} WHERE status=1 ORDER BY nid DESC");
104                  $nids = array();                  $nids = array();
105                  while($node = db_fetch_array($result)){                  while($node = db_fetch_array($result)){
106                          $nids['node/' . $node['nid']] = 'page' . $node['nid'] . '.html';                          $url = url('node/' . $node['nid']);
107                            if(strpos(' ' . $url,'/?q=') != 0){
108                                    $url = substr($url,4 + strpos($url,'/?q='));
109                            }
110                            if($url == 'node/' . $node['nid']){
111                                    $nids['node/' . $node['nid']] = 'page' . $node['nid'] . '.html';
112                            }else{
113                                    $nids[$url] = $url . '.html';
114                                    $nids['node/' . $node['nid']] = $url . '.html';
115                            }
116                  }                  }
117                  //run through all the nodes and render pages to add to the zip file                  //run through all the nodes and render pages to add to the zip file
118                  $result = db_query("SELECT nid FROM node WHERE status=1 ORDER BY nid");                  $result = db_query("SELECT nid FROM {node} WHERE status=1 ORDER BY nid DESC");
119                  while($node = db_fetch_array($result)){                  while($node = db_fetch_array($result)){
120                          $drupal_site = drupal_http_request($root . base_path() . "index.php?q=node/" . $node['nid']);                          $drupal_site = drupal_http_request($root . "index.php?q=node/" . $node['nid']);
121                            //drupal_set_message($root . "index.php?q=node/" . $node['nid']);
122                          $data = $drupal_site->data;                          $data = $drupal_site->data;
123                          //strip out file paths that have the full server in them                          //strip out file paths that have the full server in them
124                          $data = str_replace($root . base_path(),"",$data);                          $data = str_replace($root . base_path(),"",$data);
                         //strip out any path that we missed that's a full one to the server  
125                          $data = str_replace($root,"",$data);                          $data = str_replace($root,"",$data);
126                          //strip out just the base_path incase it was found without a full qualified path like /mysite/files/  
                         $data = str_replace(base_path(),"",$data);  
127                          //strip out just the node/ if it's left over and replace it with the correct form of the link so that they actually find each other                          //strip out just the node/ if it's left over and replace it with the correct form of the link so that they actually find each other
128                          foreach($nids as $key => $nidpath){                          foreach($nids as $key => $nidpath){
129                                  $data = str_replace($key,$nidpath,$data);                                  //get rid of a base path if there is one
130                                  //account for clean URLs turned off                                  if(base_path() != '/'){
131                                            $data = str_replace(base_path(),'',$data);
132                                    }
133                                    //account for links back to home where they are just a backslash cause it's at the root
134                                    $data = str_replace('index.php/?q=' . $key,$nidpath,$data);
135                                  $data = str_replace('index.php?q=' . $key,$nidpath,$data);                                  $data = str_replace('index.php?q=' . $key,$nidpath,$data);
136                                    $data = str_replace('/?q=' . $key,$nidpath,$data);
137                                    $data = str_replace('?q=' . $key,$nidpath,$data);
138                          }                          }
139                          $data = str_replace('?q=','',$data);                          $data = str_replace('?q=','',$data);
140                          $file = fopen($export_path . "/page" . $node['nid'] . ".html","w");                          $data = str_replace('<a href="/"','<a href="index.html"',$data);
141                            $data = str_replace('<a href=""','<a href="index.html"',$data);
142                            $file = fopen($export_path . "/" . $nids['node/' . $node['nid']],"w");
143                          fwrite($file,$data);                          fwrite($file,$data);
144                          fclose($file);                          fclose($file);
145                  }                  }
146    
147                  $drupal_site = drupal_http_request($root . base_path() . "index.php");                  $drupal_site = drupal_http_request($root . "index.php");
148                  $data = $drupal_site->data;                  $data = $drupal_site->data;
149                  //strip out file paths that have the full server in them                  //strip out file paths that have the full server in them
150                  $data = str_replace($root . base_path(),"",$data);                  //$data = str_replace($root . base_path(),"",$data);
151                  //strip out any path that we missed that's a full one to the server                  //$data = str_replace($root,"",$data);
                 $data = str_replace($root,"",$data);  
                 //strip out just the base_path incase it was found without a full qualified path like /mysite/files/  
                 $data = str_replace(base_path(),"",$data);  
152                  //strip out just the node/ if it's left over and replace it with the correct form of the link so that they actually find each other                  //strip out just the node/ if it's left over and replace it with the correct form of the link so that they actually find each other
153                  foreach($nids as $key => $nidpath){                  foreach($nids as $key => $nidpath){
154                          $data = str_replace($key,$nidpath,$data);                          if(base_path() != '/'){
155                          //account for clean URLs turned off                                  $data = str_replace(base_path(),'',$data);
156                            }
157                            //account for links back to home where they are just a backslash cause it's at the root
158                            $data = str_replace('index.php/?q=' . $key,$nidpath,$data);
159                          $data = str_replace('index.php?q=' . $key,$nidpath,$data);                          $data = str_replace('index.php?q=' . $key,$nidpath,$data);
160                            $data = str_replace('/?q=' . $key,$nidpath,$data);
161                            $data = str_replace('?q=' . $key,$nidpath,$data);
162                  }                  }
163                  $data = str_replace('?q=','',$data);                  $data = str_replace('?q=','',$data);
164                    //try to account for links to nowhere because they should point Home
165                    $data = str_replace('<a href="/"','<a href="index.html"',$data);
166                    $data = str_replace('<a href=""','<a href="index.html"',$data);
167                  $file = fopen($export_path . "/index.html","w");                  $file = fopen($export_path . "/index.html","w");
168                  fwrite($file,$data);                  fwrite($file,$data);
169                  fclose($file);                  fclose($file);
170                    //turn clean URLs back on if it was off temporarily
171                    if($clean){
172                            variable_set('clean_url',1);
173                    }
174                  //need to generate a list of modules and themes to copy as well as files directory except for html_export folder                  //need to generate a list of modules and themes to copy as well as files directory except for html_export folder
175                  drupal_set_message("If you don't see any errors the site was exported successfully! <a href='" . base_path() . substr($export_path,strpos($export_path,$dir)) . "/index.html' target='_blank'>Click</a> here to access the export.");                  drupal_set_message("If you don't see any errors the site was exported successfully! <a href='" . base_path() . substr($export_path,strpos($export_path,$dir)) . "/index.html' target='_blank'>Click</a> here to access the export.");
176          }          }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.2