Skip to content

Commit b3104ba

Browse files
committed
Subiento TinyULL
0 parents  commit b3104ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+9286
-0
lines changed

LICENSE

Lines changed: 662 additions & 0 deletions
Large diffs are not rendered by default.

README

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
============================================================================
3+
TinyULL, the URL shortener only for who you want.
4+
Copyright (C) 2010 Eduardo Nacimiento García
5+
6+
TinyULL is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU Affero General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU Affero General Public License for more details.
15+
16+
You should have received a copy of the GNU Affero General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
============================================================================
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Filters added to this controller apply to all controllers in the application.
2+
# Likewise, all the methods added will be available for all controllers.
3+
4+
class ApplicationController < ActionController::Base
5+
helper :all # include all helpers, all the time
6+
protect_from_forgery # See ActionController::RequestForgeryProtection for details
7+
8+
# Scrub sensitive parameters from your log
9+
# filter_parameter_logging :password
10+
end
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
class TinyullsController < ApplicationController
2+
# GET /tinyulls
3+
# GET /tinyulls.xml
4+
def index
5+
@tinyull = Tinyull.new
6+
if !params[:url].nil? && !params[:url].empty?
7+
redirect_to :action => :create, :longurl => params[:url], :html => {:method => :post}
8+
else
9+
respond_to do |format|
10+
format.html # new.html.erb
11+
end
12+
end
13+
end
14+
15+
# GET /tinyulls/1
16+
# GET /tinyulls/1.xml
17+
def show
18+
@tinyull = Tinyull.find_by_shorturl(params[:id])
19+
if @tinyull.blank?
20+
redirect_to tinyulls_path
21+
else
22+
if !params[:redirect].nil? && !params[:redirect].empty? && params[:redirect] == "no"
23+
respond_to do |format|
24+
format.html # show.html.erb
25+
end
26+
else
27+
headers["Status"] = "301 Moved Permanently"
28+
redirect_to @tinyull[:longurl]
29+
end
30+
end
31+
end
32+
33+
# GET /tinyulls/list/all
34+
def list
35+
@tinyulls = Tinyull.all
36+
respond_to do |format|
37+
format.html # list.html.erb
38+
end
39+
end
40+
41+
42+
# POST /tinyulls
43+
# POST /tinyulls.xml
44+
def create
45+
if !params[:longurl].nil? && !params[:longurl].empty?
46+
@longurl_tmp = params[:longurl]
47+
@longurl_tmp.each do |tmp|
48+
if @longurl.nil?
49+
@longurl = tmp
50+
else
51+
@longurl += "/"+tmp
52+
end
53+
end
54+
elsif !params[:tinyull][:longurl].nil? && !params[:tinyull][:longurl].empty?
55+
@longurl = params[:tinyull][:longurl]
56+
else
57+
redirect_to (tinyulls_path) and return
58+
end
59+
if !@longurl.nil? && !(@longurl =~ /https?:\/\//)
60+
@longurl = "http://"+@longurl
61+
end
62+
@search = Tinyull.find_by_sql(['select * from tinyulls where longurl LIKE ? ', "#{@longurl}"]);
63+
if @search.empty?
64+
@tinyull = Tinyull.new(:longurl => @longurl)
65+
if @tinyull.save
66+
@shorturl = @tinyull.id.to_s(36)
67+
@tinyull.shorturl = @shorturl
68+
if @tinyull.save
69+
if !params[:out].nil? && !params[:out].empty?
70+
render :text => "t.ull.es/"+@tinyull.shorturl
71+
else
72+
respond_to do |format|
73+
format.html { render :action => "show", :id => Tinyull.id}
74+
end
75+
end
76+
end
77+
else
78+
redirect_to (tinyulls_path) and return
79+
end
80+
else
81+
@tinyull = @search[0]
82+
if !params[:out].nil? && !params[:out].empty?
83+
render :text => "t.ull.es/"+@search[0].shorturl
84+
else
85+
respond_to do |format|
86+
format.html { render :action => "show", :id => @search[0].id}
87+
end
88+
end
89+
end
90+
end
91+
92+
def new
93+
redirect_to :action => :show, :id => 'new'
94+
end
95+
96+
97+
# DELETE /tinyulls/1
98+
# DELETE /tinyulls/1.xml
99+
def destroy
100+
@tinyull = Tinyull.find(params[:id])
101+
@tinyull.destroy
102+
103+
respond_to do |format|
104+
format.html { redirect_to :action => :list }
105+
end
106+
end
107+
end

app/helpers/application_helper.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Methods added to this helper will be available to all templates in the application.
2+
module ApplicationHelper
3+
end

app/helpers/tinyulls_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module TinyullsHelper
2+
end

app/models/tinyull.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Tinyull < ActiveRecord::Base
2+
validates_presence_of :longurl
3+
validates_format_of :longurl, :with => /^(http:\/\/|https:\/\/|\w*[^:]\w)[^&\?\/]+\.ull\.es(\/\S*$|\?\S*$|$)/i
4+
5+
end

app/views/layouts/tinyulls.html.erb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
2+
3+
<html lang="es-ES">
4+
<head>
5+
<%= stylesheet_link_tag 'style' %>
6+
7+
8+
<title>Universidad de La Laguna - TinyULL</title></head>
9+
10+
<body class="login">
11+
12+
13+
<div id="baselogin">
14+
<div id="contenidologin">
15+
<div id="logo">
16+
<a href="http://t.ull.es" target=""><img src="/images/tiny2.png" alt="TinyULL" width="200" border="0" title="" /></a></div>
17+
<div id="formulario">
18+
<h1>Servicio de enlaces cortos<br />
19+
</h1>
20+
<p>&nbsp;</p>
21+
<p>&nbsp;</p>
22+
<p>&nbsp;</p>
23+
<p>&nbsp;</p>
24+
<p>&nbsp;</p>
25+
<p>&nbsp;</p>
26+
<div id="content">
27+
<p style="color: green"><%= flash[:notice] %></p>
28+
<%= yield %>
29+
</div>
30+
<p>&nbsp;</p>
31+
</div>
32+
</div>
33+
<div id="rightlogin"></div>
34+
<div id="bottomlogin"></div>
35+
</div>
36+
37+
38+
</body>
39+
</html>

app/views/shared/_social.html.erb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!-- application URL -->
2+
<% @url_app = url_for(:only_path => false) %>
3+
<% @url_app = @url_app.gsub('%20', '_') %>
4+
5+
6+
<p>
7+
<%= link_to image_tag("fb.png"), "http://www.facebook.com/share.php?u=#{@final_url}" %>
8+
<%= link_to image_tag("twitter.png"), "http://twitter.com/home?status=#{@final_url}" %>
9+
<%= link_to image_tag("identica.png"), "http://identi.ca/index.php?action=newnotice&status_textarea=#{@final_url}" %>
10+
<%= link_to image_tag("buzz.png"), "http://www.google.com/buzz/post?url=#{@final_url}" %>
11+
<%= link_to image_tag("ff.png"), "http://friendfeed.com/?url=#{@final_url}" %>
12+
<%= link_to image_tag("delicious.png"), "http://del.icio.us/post?url=#{@final_url}" %>
13+
<%= link_to image_tag("linkedin2.png"), "http://www.linkedin.com/shareArticle?mini=true&url=#{@final_url}" %>
14+
</p>

app/views/tinyulls/edit.html.erb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<h1>Editing tinyull</h1>
2+
3+
<% form_for(@tinyull) do |f| %>
4+
<%= f.error_messages %>
5+
6+
<p>
7+
<%= f.label :shorturl %><br />
8+
<%= f.text_field :shorturl %>
9+
</p>
10+
<p>
11+
<%= f.label :longurl %><br />
12+
<%= f.text_field :longurl %>
13+
</p>
14+
<p>
15+
<%= f.submit 'Update' %>
16+
</p>
17+
<% end %>
18+
19+
<%= link_to 'Show', @tinyull %> |
20+
<%= link_to 'Back', tinyulls_path %>

0 commit comments

Comments
 (0)