]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - admin/install.php
Cleaner logic in HTML functions and admin index: more filters, less hardcoded HTML...
[Github/YOURLS.git] / admin / install.php
1 <?php\r
2 define( 'YOURLS_INSTALLING', true );\r
3 define( 'YOURLS_ADMIN', true );\r
4 require_once( dirname(dirname(__FILE__)).'/includes/load-yourls.php' );\r
5 require_once( YOURLS_INC.'/functions-install.php' );\r
6 \r
7 $error = array();\r
8 $warning = array();\r
9 $success = array();\r
10 \r
11 // Check pre-requisites\r
12 if ( !yourls_check_database_version() )\r
13         $error[] = 'MySQL version is too old. Ask your server admin for an upgrade.';\r
14 \r
15 if ( !yourls_check_php_version() )\r
16         $error[] = 'PHP version is too old. Ask your server admin for an upgrade.';\r
17 \r
18 // Check additional stuff\r
19 if ( !yourls_check_curl() )\r
20         $warning[] = 'PHP extension <tt>cURL</tt> is not installed. This server won\'t be able to use the remote API';\r
21 \r
22 // Is YOURLS already installed ?\r
23 if ( yourls_is_installed() ) {\r
24         $error[] = 'YOURLS already installed.';\r
25         // check if .htaccess exists, recreate otherwise. No error checking.\r
26         if( !file_exists( YOURLS_ABSPATH.'/.htaccess' ) ) {\r
27                 yourls_create_htaccess();\r
28         }\r
29 }\r
30 \r
31 // Start install if possible and needed\r
32 if ( isset($_REQUEST['install']) && count( $error ) == 0 ) {\r
33         // Create/update .htaccess file\r
34         if ( yourls_create_htaccess() ) {\r
35                 $success[] = 'File <tt>.htaccess</tt> successfully created/updated.';\r
36         } else {\r
37                 $warning[] = 'Could not write file <tt>.htaccess</tt> in YOURLS root directory. You will have to do it manually. See <a href="http://yourls.org/htaccess">how</a>.';\r
38         }\r
39 \r
40         // Create SQL tables\r
41         $install = yourls_create_sql_tables();\r
42         if ( isset( $install['error'] ) )\r
43                 $error = array_merge( $error, $install['error'] );\r
44         if ( isset( $install['success'] ) )\r
45                 $success = array_merge( $success, $install['success'] );\r
46 }\r
47 \r
48 \r
49 // Start output\r
50 yourls_html_head( 'install', 'Install YOURLS' );\r
51 ?>\r
52 <div id="login">\r
53         <form method="post" action="?"><?php // reset any QUERY parameters ?>\r
54                 <p>\r
55                         <img src="<?php echo YOURLS_SITE; ?>/images/yourls-logo.png" alt="YOURLS" title="YOURLS" />\r
56                 </p>\r
57                 <?php\r
58                         // Print errors, warnings and success messages\r
59                         foreach ( array ('error', 'warning', 'success') as $info ) {\r
60                                 if ( count( $$info ) > 0 ) {\r
61                                         echo "<ul class='$info'>";\r
62                                         foreach( $$info as $msg ) {\r
63                                                 echo '<li>'.$msg."</li>\n";\r
64                                         }\r
65                                         echo '</ul>';\r
66                                 }\r
67                         }\r
68 \r
69                         // Display install button or link to admin area if applicable\r
70                         if( !yourls_is_installed() && !isset($_REQUEST['install']) ) {\r
71                                 echo '<p>&nbsp;</p><p style="text-align: center;"><input type="submit" name="install" value="Install YOURLS" class="button" /></p>';\r
72                         } else {\r
73                                 if( count($error) == 0 )\r
74                                         echo '<p>&nbsp;</p><p style="text-align: center;">&raquo; <a href="'.yourls_admin_url().'" title="YOURLS Administration Page">YOURLS Administration Page</a></p>';\r
75                         }\r
76                 ?>\r
77         </form>\r
78 </div>\r
79 <?php yourls_html_footer(); ?>\r