install/includes/payload.php
changeset 924 142a29b583f9
parent 876 aed15c337b72
child 984 18f5a15b810c
equal deleted inserted replaced
923:9ef3ccac13de 924:142a29b583f9
   112   catch ( Exception $e )
   112   catch ( Exception $e )
   113   {
   113   {
   114     echo "<pre>$e</pre>";
   114     echo "<pre>$e</pre>";
   115     return false;
   115     return false;
   116   }
   116   }
   117   
       
   118   $wkt = ENANO_ROOT . "/language/{$languages[$lang_id]['dir']}/install/mainpage-default.wkt";
       
   119   if ( !file_exists( $wkt ) )
       
   120   {
       
   121     echo '<div class="error-box">Error: could not locate wikitext for main page (' . $wkt . ')</div>';
       
   122     return false;
       
   123   }
       
   124   $wkt = @file_get_contents($wkt);
       
   125   if ( empty($wkt) )
       
   126     return false;
       
   127   
       
   128   $wkt = $db->escape($wkt);
       
   129   
   117   
   130   $vars = array(
   118   $vars = array(
   131       'TABLE_PREFIX'         => table_prefix,
   119       'TABLE_PREFIX'         => table_prefix,
   132       'SITE_NAME'            => $db->escape($_POST['site_name']),
   120       'SITE_NAME'            => $db->escape($_POST['site_name']),
   133       'SITE_DESC'            => $db->escape($_POST['site_desc']),
   121       'SITE_DESC'            => $db->escape($_POST['site_desc']),
   141       'ADMIN_PASS_SALT'      => $hmac_secret,
   129       'ADMIN_PASS_SALT'      => $hmac_secret,
   142       'ADMIN_EMAIL'          => $db->escape($_POST['email']),
   130       'ADMIN_EMAIL'          => $db->escape($_POST['email']),
   143       'REAL_NAME'            => '', // This has always been stubbed.
   131       'REAL_NAME'            => '', // This has always been stubbed.
   144       'ADMIN_EMBED_PHP'      => strval(AUTH_DISALLOW),
   132       'ADMIN_EMBED_PHP'      => strval(AUTH_DISALLOW),
   145       'UNIX_TIME'            => strval(time()),
   133       'UNIX_TIME'            => strval(time()),
   146       'MAIN_PAGE_CONTENT'    => $wkt,
       
   147       'IP_ADDRESS'           => $db->escape($_SERVER['REMOTE_ADDR'])
   134       'IP_ADDRESS'           => $db->escape($_SERVER['REMOTE_ADDR'])
   148     );
   135     );
   149   
   136   
   150   $sql_parser->assign_vars($vars);
   137   $sql_parser->assign_vars($vars);
   151   return true;
   138   return true;
   340     $db->_die();
   327     $db->_die();
   341   
   328   
   342   list($lang_id_int) = $db->fetchrow_num();
   329   list($lang_id_int) = $db->fetchrow_num();
   343   $db->free_result();
   330   $db->free_result();
   344   setConfig('default_language', $lang_id_int);
   331   setConfig('default_language', $lang_id_int);
       
   332   
       
   333   return true;
       
   334 }
       
   335 
       
   336 function stg_add_content()
       
   337 {
       
   338   global $db, $session, $paths, $template, $plugins; // Common objects
       
   339   global $cache;
       
   340   
       
   341   global $languages;
       
   342   global $lang_id;
       
   343   $lang_info =& $languages[$lang_id];
       
   344   if ( !is_array($lang_info) )
       
   345     return false;
       
   346   
       
   347   if ( $_POST['default_content_type'] === 'tutorial' )
       
   348   {
       
   349     $dir = ENANO_ROOT . "/language/{$lang_info['dir']}/install/default-tutorial";
       
   350   }
       
   351   else
       
   352   {
       
   353     $dir = ENANO_ROOT . "/language/{$lang_info['dir']}/install/default-blank";
       
   354   }
       
   355   
       
   356   if ( !$dr = @opendir($dir) )
       
   357     return false;
       
   358   
       
   359   while ( $dh = @readdir($dr) )
       
   360   {
       
   361     if ( !preg_match('/\.txt$/', $dh) )
       
   362       continue;
       
   363     
       
   364     $page_contents = @file_get_contents("$dir/$dh");
       
   365     if ( empty($page_contents) )
       
   366       return false;
       
   367     
       
   368     $page_name = preg_replace('/\.txt$/', '', $dh);
       
   369     
       
   370     if ( !install_primitive_page_creator($page_name, 'Article', $page_contents) )
       
   371       return false;
       
   372   }
       
   373   
       
   374   closedir($dr);
       
   375   
       
   376   $cache->purge('page_meta');
       
   377   
       
   378   return true;
       
   379 }
       
   380 
       
   381 function install_primitive_page_creator($page_id, $namespace, $content)
       
   382 {
       
   383   global $db, $session, $paths, $template, $plugins; // Common objects
       
   384   
       
   385   $page_title = $db->escape(str_replace('_', ' ', dirtify_page_id($page_id)));
       
   386   $author = $db->escape($_POST['username']);
       
   387   $page_id = $db->escape($page_id);
       
   388   $namespace = $db->escape($namespace);
       
   389   // yes, we do probably want strip_all_php ON.
       
   390   $content = RenderMan::preprocess_text($content, true, true);
       
   391   $now = time();
       
   392   
       
   393   // query 1: logs
       
   394   $q = $db->sql_query('INSERT INTO ' . table_prefix . "logs(time_id, date_string, log_type, action, page_id, namespace, author, page_text) VALUES\n"
       
   395                     . "  ( $now, 'DEPRECATED', 'page', 'edit', '$page_id', '$namespace', '$author', '$content');");
       
   396   if ( !$q )
       
   397   {
       
   398     echo $db->get_error();
       
   399     return false;
       
   400   }
       
   401   
       
   402   // query 2: page_text
       
   403   $q = $db->sql_query('INSERT INTO ' . table_prefix . "page_text(page_id, namespace, page_text) VALUES\n"
       
   404                     . "  ( '$page_id', '$namespace', '$content');");
       
   405   if ( !$q )
       
   406   {
       
   407     echo $db->get_error();
       
   408     return false;
       
   409   }
       
   410   
       
   411   // query 3: pages
       
   412   $q = $db->sql_query('INSERT INTO ' . table_prefix . "pages(page_order, name, urlname, namespace, special, visible, comments_on, protected, delvotes, delvote_ips) VALUES\n"
       
   413                     . "  (NULL, '$page_title', '$page_id', '$namespace', 0, 1, 1, 1, 0, '');");
       
   414   if ( !$q )
       
   415   {
       
   416     echo $db->get_error();
       
   417     return false;
       
   418   }
   345   
   419   
   346   return true;
   420   return true;
   347 }
   421 }
   348 
   422 
   349 function stg_init_logs()
   423 function stg_init_logs()