Skip to content

Commit

Permalink
Merge branch 'master' into delete-link-confirm
Browse files Browse the repository at this point in the history
  • Loading branch information
overint authored Mar 29, 2018
2 parents 262c849 + 8c0d012 commit 40e961e
Show file tree
Hide file tree
Showing 19 changed files with 151 additions and 35 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<!--- Provide a general summary of the issue in the Title above -->
<!--- IMPORTANT: Please follow the format displayed in this template, or your ticket may be ignored. -->

## Expected Behavior
<!--- If you're describing a bug, tell us what should happen -->
Expand Down
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# [![Logo](http://i.imgur.com/aOtrJNz.png)](https://polrproject.org)
<img src="https://i.imgur.com/ckI6GTu.png" width="350px" alt="Polr Logo" />


:aerial_tramway: A modern, minimalist, and lightweight URL shortener.

[![GitHub license](https://img.shields.io/badge/license-GPLv2%2B-blue.svg)]()
[![GitHub release](https://img.shields.io/github/release/cydrobolt/polr.svg)](https://github.com/cydrobolt/polr/releases)
[![Builds status](https://travis-ci.org/cydrobolt/polr.svg)](https://travis-ci.org/cydrobolt/polr)
[![Builds status](https://travis-ci.org/cydrobolt/polr.svg)](https://travis-ci.org/cydrobolt/polr)
[![Docs](https://img.shields.io/badge/docs-latest-brightgreen.svg?style=flat)](http://polr.readthedocs.org/en/latest/)


Expand All @@ -16,7 +17,7 @@ Polr is an intrepid, self-hostable open-source link shortening web application w

Polr is written in PHP and Lumen, using MySQL as its primary database.

- To get started with Polr on your server, check out the [installation guide](http://docs.polrproject.org/en/latest/user-guide/installation/). You can clone this repository, or download a [release](https://github.com/cydrobolt/polr/releases).
- To get started with Polr on your server, check out the [installation guide](http://docs.polrproject.org/en/latest/user-guide/installation/). You can clone this repository, or download a [release](https://github.com/cydrobolt/polr/releases).
- To get started with the Polr API, check out the [API guide](http://docs.polrproject.org/en/latest/developer-guide/api/).


Expand Down Expand Up @@ -44,11 +45,17 @@ There are breaking changes between 2.x and 1.x; it is not yet possible to automa

* Safari - [Polr.safariextension](https://github.com/cleverdevil/Polr.safariextension)

#### Sponsors
#### Libraries

* Python - [mypolr](https://github.com/fauskanger/mypolr)

#### Acknowledgements
We would like to thank Oregon State University's Open Source Lab for providing resources for our infrastructure. The Polr website and demo are hosted on their infrastructure.

<a href="//osuosl.org"><img height="100em" src="http://i.imgur.com/1VtLxyX.png" /></a>

Thank you to [lastspark](https://thenounproject.com/lastspark/) for providing our logo's icon.

#### Versioning

Polr uses [Semantic Versioning](http://semver.org/)
Expand All @@ -57,7 +64,7 @@ Polr uses [Semantic Versioning](http://semver.org/)
#### License


Copyright (C) 2013-2017 Chaoyi Zha
Copyright (C) 2013-2018 Chaoyi Zha

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
Expand Down
10 changes: 7 additions & 3 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function render($request, Exception $e)
return redirect()->to(env('SETTING_INDEX_REDIRECT'));
}
// Otherwise, show a nice error page
return view('errors.404');
return response(view('errors.404'), 404);
}
if ($e instanceof HttpException) {
// Handle HTTP exceptions thrown by public-facing controllers
Expand All @@ -60,11 +60,15 @@ public function render($request, Exception $e)

if ($status_code == 500) {
// Render a nice error page for 500s
return view('errors.500');
return response(view('errors.500'), 500);
}
else {
// If not 500, render generic page
return response(view('errors.generic', ['status_code' => $status_code, 'status_message' => $status_message]), $status_code);
return response(
view('errors.generic', [
'status_code' => $status_code,
'status_message' => $status_message
]), $status_code);
}
}
if ($e instanceof ApiException) {
Expand Down
6 changes: 5 additions & 1 deletion app/Helpers/ApiHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ public static function checkUserApiQuota($username) {
$api_quota = env('SETTING_ANON_API_QUOTA') ?: 5;
}

if ($api_quota < 0) {
return false;
}

$links_last_minute = Link::where('is_api', 1)
->where('creator', $username)
->where('created_at', '>=', $last_minute)
->count();

return ($api_quota > -1 && $links_last_minute >= $api_quota);
return $links_last_minute >= $api_quota;
}
}
13 changes: 9 additions & 4 deletions app/Http/Controllers/AdminPaginationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class AdminPaginationController extends Controller {
/* Cell rendering functions */

public function renderLongUrlCell($link) {
return '<a target="_blank" title="' . e($link->long_url) . '" href="'. $link->long_url .'">' . str_limit($link->long_url, 50) . '</a>
<a class="btn btn-primary btn-xs edit-long-link-btn" ng-click="editLongLink(\'' . $link->short_url . '\', \'' . $link->long_url . '\')"><i class="fa fa-edit edit-link-icon"></i></a>';
return '<a target="_blank" title="' . e($link->long_url) . '" href="'. e($link->long_url) .'">' . e(str_limit($link->long_url, 50)) . '</a>
<a class="btn btn-primary btn-xs edit-long-link-btn" ng-click="editLongLink(\'' . e($link->short_url) . '\', \'' . e($link->long_url) . '\')"><i class="fa fa-edit edit-link-icon"></i></a>';
}

public function renderClicksCell($link) {
Expand Down Expand Up @@ -123,6 +123,12 @@ public function renderToggleLinkActiveCell($link) {
</a>';
}

public function renderControlLinkCell($link){
return '<div class="btn-group" role="group">
' . $this->renderToggleLinkActiveCell($link) . $this->renderDeleteLinkCell($link) . '
</div>';
}

/* DataTables bindings */

public function paginateAdminUsers(Request $request) {
Expand All @@ -143,8 +149,7 @@ public function paginateAdminLinks(Request $request) {

$admin_links = Link::select(['short_url', 'long_url', 'clicks', 'created_at', 'creator', 'is_disabled']);
return Datatables::of($admin_links)
->addColumn('disable', [$this, 'renderToggleLinkActiveCell'])
->addColumn('delete', [$this, 'renderDeleteLinkCell'])
->addColumn('control', [$this, 'renderControlLinkCell'])
->editColumn('clicks', [$this, 'renderClicksCell'])
->editColumn('long_url', [$this, 'renderLongUrlCell'])
->escapeColumns(['short_url', 'creator'])
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function displayLostPasswordPage(Request $request) {

public function performLogoutUser(Request $request) {
$request->session()->forget('username');
$request->session()->forget('role');
return redirect()->route('index');
}

Expand Down
36 changes: 36 additions & 0 deletions database/migrations/2017_12_21_095425_create_api_quota_index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateApiQuotaIndex extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('links', function (Blueprint $table)
{
$table->index(
['created_at', 'creator', 'is_api'],
'api_quota_index'
);
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('links', function (Blueprint $table)
{
$table->dropIndex('api_quota_index');
});
}
}
9 changes: 3 additions & 6 deletions docs/developer-guide/libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ To interact with Polr's API, you may opt to use a library or write your own inte
As not all languages and frameworks are currently supported by a library, it is encouraged
that you take a look at the [API documentation](api/) to integrate Polr into your application.

### Official Libraries
- there are no official libraries for Polr 2.0 yet.

### Unofficial libraries
- there are no unofficial libraries for Polr 2.0 yet.
- perhaps you'd like to write one? Send a PR to add your library to this page.
## Unofficial libraries
### Python
- [mypolr](https://github.com/fauskanger/mypolr) is a Python 3 package for interacting with the Polr 2.0 API. ([Documentation](https://mypolr.readthedocs.io))
Binary file modified docs/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions public/css/about.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
}

.logo-img {
width: 18em;
width: 17em;
}

.logo-well {
width: 19em;
width: 20.5em;

-webkit-animation: colorpulse 20s infinite;
animation: colorpulse 20s infinite;
Expand Down
2 changes: 1 addition & 1 deletion public/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ input.api-quota {
display: inline;
width: 9em;
font-size: .85em;
height: .85em;
height: auto;
padding-left: 0.8em;
}

Expand Down
21 changes: 20 additions & 1 deletion public/css/shorten_result.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,29 @@

}

.back-btn {
.btn {
margin-top: 30px;
}

.content-div {
text-align: center;
}

.qr-code-container {
display: none;
margin-top: 2em;
}

.qr-code-container img {
display: inline !important;
}

.input-group {
width: 40vw;
margin: 0 auto;
}

.input-group-addon {
padding: 0px 10px;
cursor: pointer;
}
Binary file modified public/img/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 5 additions & 8 deletions public/js/AdminCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,12 @@ polr.controller('AdminCtrl', function($scope, $compile, $timeout) {
"ajax": BASE_API_PATH + 'admin/get_admin_links',

"columns": [
{className: 'wrap-text', data: 'short_url', name: 'short_url'},
{className: 'wrap-text', data: 'short_url', name: 'short_url', width: '10%'},
{className: 'wrap-text', data: 'long_url', name: 'long_url'},
{data: 'clicks', name: 'clicks'},
{data: 'created_at', name: 'created_at'},
{data: 'creator', name: 'creator'},

{data: 'disable', name: 'disable', orderable: false, searchable: false},
{data: 'delete', name: 'delete', orderable: false, searchable: false}

{data: 'clicks', name: 'clicks', width: '10%'},
{data: 'created_at', name: 'created_at', width: '18%'},
{data: 'creator', name: 'creator', width: '20%'},
{data: 'control', name: 'control', orderable: false, searchable: false, width: '15%'},
]
}, datatables_config));
}
Expand Down
Loading

0 comments on commit 40e961e

Please sign in to comment.