]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - admin/install.php
- New functions: yourls_nonce_url, yourls_nonce_field, yourls_add_query_arg
[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 \r
26 // Start install if possible and needed\r
27 if ( isset($_REQUEST['install']) && count( $error ) == 0 ) {\r
28         // Create/update .htaccess file\r
29         if ( yourls_create_htaccess() ) {\r
30                 $success[] = 'File <tt>.htaccess</tt> successfully created/updated.';\r
31         } else {\r
32                 $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
33         }\r
34 \r
35         // Create SQL tables\r
36         $install = yourls_create_sql_tables();\r
37         if ( isset( $install['error'] ) )\r
38                 $error = array_merge( $error, $install['error'] );\r
39         if ( isset( $install['success'] ) )\r
40                 $success = array_merge( $success, $install['success'] );\r
41 }\r
42 \r
43 \r
44 // Start output\r
45 yourls_html_head( 'install', 'Install YOURLS' );\r
46 ?>\r
47 <div id="login">\r
48         <form method="post" action="?"><?php // reset any QUERY parameters ?>\r
49                 <p>\r
50                         <img src="<?php echo YOURLS_SITE; ?>/images/yourls-logo.png" alt="YOURLS" title="YOURLS" />\r
51                 </p>\r
52                 <?php\r
53                         // Print errors, warnings and success messages\r
54                         foreach ( array ('error', 'warning', 'success') as $info ) {\r
55                                 if ( count( $$info ) > 0 ) {\r
56                                         echo "<ul class='$info'>";\r
57                                         foreach( $$info as $msg ) {\r
58                                                 echo '<li>'.$msg."</li>\n";\r
59                                         }\r
60                                         echo '</ul>';\r
61                                 }\r
62                         }\r
63 \r
64                         // Display install button or link to admin area if applicable\r
65                         if( !yourls_is_installed() && !isset($_REQUEST['install']) ) {\r
66                                 echo '<p>&nbsp;</p><p style="text-align: center;"><input type="submit" name="install" value="Install YOURLS" class="button" /></p>';\r
67                         } else {\r
68                                 if( count($error) == 0 )\r
69                                         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
70                         }\r
71                 ?>\r
72         </form>\r
73 </div>\r
74 <?php yourls_html_footer(); ?>\r