File: Skin.pm

package info (click to toggle)
pnopaste 1.8-4
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 344 kB
  • sloc: perl: 1,056; sh: 55; sql: 39; makefile: 8
file content (93 lines) | stat: -rw-r--r-- 1,692 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package Skin;

# This file is part of the pnopaste program
# Copyright (C) 2008-2021 Patrick Matthäi <pmatthaei@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

use warnings;
use strict;
use lib::Database;

# Default (fallback) settings.
my $CSS_Default		= 'default';
my $Title_Default	= 'Perl Nopaste';


### Returns available skins in an array.
sub Get_Available_Skins {
	my @Skins;

	opendir(R,'./skins/');

	while(my $File = readdir(R)){
		if(-e './skins/' . $File and $File =~ /^.*\.css$/){
			$File =~ s/\.css$//;
			push(@Skins, $File);
		}
	}

	closedir(R);

	return @Skins;
}


### Returns the HTML title.
sub Get_Title {
	my $Query = 'SELECT title FROM settings LIMIT 1';
	$Query = $Database::dbh->prepare($Query);
	$Query->execute();

	my $Result = $Query->fetchrow_hashref();
	my $Title = $Result->{'title'};

	if(!defined $Title){
		return $Title_Default;
	} else {
		return $Title;
	}
}


### Checks if a skin is valid.
sub Is_Valid {
	my($Check) = @_;

	return 0 if !$Check;

	my @Skinlist = Get_Available_Skins();

	foreach my $Tmp (@Skinlist){
		if($Tmp eq $Check){
			# Valid.
			return 1;
		}
	}

	# Invalid.
	return 0;
}


### Gets the saved skin from the database.
sub Get_Skin {
	my $Query = 'SELECT style FROM settings LIMIT 1';
	$Query = $Database::dbh->prepare($Query);
	$Query->execute();

	my $Result = $Query->fetchrow_hashref();
	my $Skin = $Result->{'style'};

	if(Is_Valid($Skin) == 0){
		return $CSS_Default;
	} else {
		return $Skin;
	}
}

1;