Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mbas-shortener
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
mbas-shortener
Commits
5725cd7e
Commit
5725cd7e
authored
Jan 26, 2016
by
Vitalik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ref
parent
5520fb2e
Pipeline
#172
skipped
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
8 deletions
+24
-8
config.php.example
config.php.example
+2
-0
helper.php
helper.php
+20
-6
install.php
install.php
+2
-2
No files found.
config.php.example
View file @
5725cd7e
...
...
@@ -2,6 +2,7 @@
return
array
(
'database'
=>
'dibi'
,
'table'
=>
'links'
,
'username'
=>
'root'
,
'password'
=>
'z'
,
);
\ No newline at end of file
helper.php
View file @
5725cd7e
<?php
$config
=
require
PATH_BASE
.
'/config.php'
;
function
connect_db
()
{
$config
=
require
PATH_BASE
.
'/config.php'
;
global
$config
;
$link
=
mysql_connect
(
'localhost'
,
$config
[
'username'
],
$config
[
'password'
]);
...
...
@@ -17,6 +19,8 @@ function connect_db()
function
load_links
()
{
global
$config
;
$list
=
array
();
$db
=
connect_db
();
...
...
@@ -25,10 +29,12 @@ function load_links()
long_url, short_url,
DATE_FORMAT(created, '%d %b %Y') AS created,
clicks
FROM
links
FROM
{
$config
[
'table'
]
}
ORDER BY id DESC"
;
$result
=
mysql_query
(
$sql
,
$db
);
if
(
!
$result
)
die
(
"mySQL error: "
.
mysql_error
());
while
(
$row
=
mysql_fetch_object
(
$result
))
{
$list
[]
=
$row
;
...
...
@@ -48,10 +54,12 @@ function isset_url($short_url)
function
get_url
(
$short_url
)
{
global
$config
;
$db
=
connect_db
();
$sql
=
"SELECT id, long_url
FROM
links
FROM
{
$config
[
'table'
]
}
WHERE short_url = '
$short_url
'
LIMIT 1"
;
...
...
@@ -68,9 +76,11 @@ function get_url($short_url)
function
delete_url
(
$id
)
{
global
$config
;
$db
=
connect_db
();
$sql
=
"DELETE FROM
links
WHERE id =
$id
"
;
$sql
=
"DELETE FROM
{
$config
[
'table'
]
}
WHERE id =
$id
"
;
mysql_query
(
$sql
);
...
...
@@ -81,9 +91,11 @@ function delete_url($id)
function
url_click
(
$id
)
{
global
$config
;
$db
=
connect_db
();
$sql
=
"UPDATE
links
$sql
=
"UPDATE
{
$config
[
'table'
]
}
SET clicks = clicks + 1
WHERE id =
$id
"
;
...
...
@@ -111,6 +123,8 @@ function validate_url($url)
function
create
(
$long_url
)
{
global
$config
;
$long_url
=
validate_url
(
$long_url
);
if
(
!
$long_url
)
return
false
;
...
...
@@ -123,7 +137,7 @@ function create($long_url)
if
(
isset_url
(
$short_url
))
return
false
;
$sql
=
"INSERT INTO
links
(long_url, short_url, created)
$sql
=
"INSERT INTO
{
$config
[
'table'
]
}
(long_url, short_url, created)
VALUES(
'
$long_url
',
'
$short_url
',
...
...
install.php
View file @
5725cd7e
...
...
@@ -28,7 +28,7 @@ if (!$db_selected) {
}
}
$sql
=
"CREATE TABLE IF NOT EXISTS `
{
$config
[
'database'
]
}
`.`
links
` (
$sql
=
"CREATE TABLE IF NOT EXISTS `
{
$config
[
'database'
]
}
`.`
{
$config
[
'table'
]
}
` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`long_url` text NOT NULL,
`short_url` text NOT NULL,
...
...
@@ -38,7 +38,7 @@ $sql = "CREATE TABLE IF NOT EXISTS `{$config['database']}`.`links` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
;
if
(
mysql_query
(
$sql
,
$link
))
{
echo
"Table `
links
` created successfully
\n
"
;
echo
"Table `
{
$config
[
'table'
]
}
` created successfully
\n
"
;
}
else
{
echo
"Error creating table: "
.
mysql_error
()
.
"
\n
"
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment