Compare commits
255 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
afa89836d2 | ||
![]() |
d25b53ab33 | ||
![]() |
f17219d054 | ||
![]() |
1583120679 | ||
![]() |
5651c47b1d | ||
![]() |
6f5e59f140 | ||
![]() |
5e1a72f22e | ||
![]() |
08cd9e7cf8 | ||
![]() |
2ad4e86ec8 | ||
![]() |
911b0be5ac | ||
![]() |
7d834a6d03 | ||
![]() |
902066ed81 | ||
![]() |
75788116ec | ||
![]() |
2ff91c0908 | ||
![]() |
57153f383c | ||
![]() |
45955a4730 | ||
![]() |
1a72664f73 | ||
![]() |
7231835bf5 | ||
![]() |
d13d6ab98e | ||
![]() |
b41c4a57fc | ||
![]() |
845b9f724a | ||
![]() |
f0dbd5e426 | ||
![]() |
3652faf8ab | ||
![]() |
8ad8b5ca6f | ||
![]() |
3dee0f4028 | ||
![]() |
8073f2ce44 | ||
![]() |
0396958944 | ||
![]() |
dabfd02776 | ||
![]() |
59858cabfe | ||
![]() |
477912bdbf | ||
![]() |
9f5393fac5 | ||
![]() |
1ae667ed5e | ||
![]() |
763bca162a | ||
![]() |
b43ca9a94e | ||
![]() |
386707c104 | ||
![]() |
86b3840278 | ||
![]() |
d5ecdf330c | ||
![]() |
734822aa8a | ||
![]() |
b54509ba51 | ||
![]() |
07d5869a1a | ||
![]() |
6f6640ae15 | ||
![]() |
4f9ec2cb82 | ||
![]() |
795308a949 | ||
![]() |
59633724c2 | ||
![]() |
022bc27612 | ||
![]() |
5ae966bfa5 | ||
![]() |
bf9ba1ad34 | ||
![]() |
1b43034c0e | ||
![]() |
53cfef9655 | ||
![]() |
d8b745cbbd | ||
![]() |
26ad4902a0 | ||
![]() |
1048548f3e | ||
![]() |
cdc56c3c0c | ||
![]() |
00d109ca82 | ||
![]() |
5d300a80ad | ||
![]() |
927d769045 | ||
![]() |
031cfb7b14 | ||
![]() |
1ce28f77ad | ||
![]() |
63e82e911c | ||
![]() |
e704a58591 | ||
![]() |
2fdcdec291 | ||
![]() |
913cc1e96f | ||
![]() |
e67dbf1e5f | ||
![]() |
206c27b444 | ||
![]() |
13eeee540f | ||
![]() |
805ef7e2a9 | ||
![]() |
791849c7c5 | ||
![]() |
e264220e8c | ||
![]() |
28eb077cc7 | ||
![]() |
b5a90af0c1 | ||
![]() |
bfd493f944 | ||
![]() |
f8056a1dc2 | ||
![]() |
0ba76adc1d | ||
![]() |
938b95691c | ||
![]() |
ebce135ebf | ||
![]() |
f63bfe21bc | ||
![]() |
e9ed83daa9 | ||
![]() |
d1614ee205 | ||
![]() |
22d2d84b1d | ||
![]() |
9f255592ff | ||
![]() |
6128fb62a8 | ||
![]() |
0a649d16b9 | ||
![]() |
58b4b869cd | ||
![]() |
f64695f42d | ||
![]() |
23fdda8abb | ||
![]() |
a55ad19c9c | ||
![]() |
6042db4f20 | ||
![]() |
e6ec593365 | ||
![]() |
2d5b8df569 | ||
![]() |
e301952470 | ||
![]() |
1a7c9e9d75 | ||
![]() |
67348c95f4 | ||
![]() |
3c1323578e | ||
![]() |
a536d0b38c | ||
![]() |
9fbb2f0869 | ||
![]() |
f8ed38f556 | ||
![]() |
92e2af5bf0 | ||
![]() |
bf105daadc | ||
![]() |
fcea47a1e8 | ||
![]() |
f27d628524 | ||
![]() |
610ff2ecad | ||
![]() |
7bb7bd47a5 | ||
![]() |
3225e9ad6a | ||
![]() |
decdb9a900 | ||
![]() |
de84d39dc3 | ||
![]() |
62b0d05364 | ||
![]() |
c690e1b813 | ||
![]() |
dc6b755dfc | ||
![]() |
aa08d4c21c | ||
![]() |
7de05ea123 | ||
![]() |
e4eacf976a | ||
![]() |
4f3cd948d9 | ||
![]() |
c840447c30 | ||
![]() |
dccc2d2586 | ||
![]() |
8c0078f3e1 | ||
![]() |
a7cacdee4f | ||
![]() |
d564d8dbe1 | ||
![]() |
7b7dbed563 | ||
![]() |
a2f6e3069e | ||
![]() |
53d6ad0c56 | ||
![]() |
a338303e0d | ||
![]() |
764b459ffd | ||
![]() |
425bba5628 | ||
![]() |
f159121b2f | ||
![]() |
046829c045 | ||
![]() |
d12b908808 | ||
![]() |
f01ecccf8c | ||
![]() |
e977266077 | ||
![]() |
287ac16d3f | ||
![]() |
4bc97d3017 | ||
![]() |
bc31c89ced | ||
![]() |
dc8aa3a93f | ||
![]() |
bc43190bd4 | ||
![]() |
446aab42d4 | ||
![]() |
ee9506ac59 | ||
![]() |
30ada7a1da | ||
![]() |
de2675426e | ||
![]() |
4d8a10643f | ||
![]() |
ff0d65a600 | ||
![]() |
58637c0d86 | ||
![]() |
2b7f57eda2 | ||
![]() |
33fbdaec98 | ||
![]() |
4419456a1d | ||
![]() |
9e0903d042 | ||
![]() |
3fdbe8986a | ||
![]() |
1987e4bc8e | ||
![]() |
446c15389b | ||
![]() |
37b523e689 | ||
![]() |
35a9a9bdd4 | ||
![]() |
fcff948182 | ||
![]() |
611b314d96 | ||
![]() |
ca570a2f69 | ||
![]() |
e87aa3b4fb | ||
![]() |
a4c80928a1 | ||
![]() |
db9ab01aa0 | ||
![]() |
4e346b0a36 | ||
![]() |
8368bbee6c | ||
![]() |
31890cba18 | ||
![]() |
f444cca623 | ||
![]() |
17f5074992 | ||
![]() |
768b5f76c7 | ||
![]() |
f9addc74f0 | ||
![]() |
284cbbed83 | ||
![]() |
b5d70e11c7 | ||
![]() |
b939cefb69 | ||
![]() |
c7a4c5e2c5 | ||
![]() |
2b3b05fe6c | ||
![]() |
945bf34185 | ||
![]() |
cda2cf8f3c | ||
![]() |
d2906509ee | ||
![]() |
333229d642 | ||
![]() |
dda4fc1fcd | ||
![]() |
1a4e7dc049 | ||
![]() |
f432bc12e1 | ||
![]() |
6c77f5b05a | ||
![]() |
a561fe6dbd | ||
![]() |
744c849473 | ||
![]() |
e155ad0ae4 | ||
![]() |
1259362364 | ||
![]() |
667db9e4e0 | ||
![]() |
fb50e282d9 | ||
![]() |
6dacf524bc | ||
![]() |
0f123b7700 | ||
![]() |
3d28060afc | ||
![]() |
90b6795f65 | ||
![]() |
65b664b678 | ||
![]() |
369f66d896 | ||
![]() |
0c61f05ffe | ||
![]() |
5548f66fd9 | ||
![]() |
56281b0f34 | ||
![]() |
2cdb68ce7e | ||
![]() |
2d8504c104 | ||
![]() |
7352ac53a6 | ||
![]() |
5423b4b11b | ||
![]() |
79c5adf495 | ||
![]() |
b3fd2fd035 | ||
![]() |
1f80e07311 | ||
![]() |
cfe7171b5f | ||
![]() |
af9735497e | ||
![]() |
86fe729403 | ||
![]() |
86d501135f | ||
![]() |
b20cb29512 | ||
![]() |
d64dece803 | ||
![]() |
5a6376c185 | ||
![]() |
06bc3461c4 | ||
![]() |
c9fc32f6a7 | ||
![]() |
91182f5c0d | ||
![]() |
f66fc0c524 | ||
![]() |
8242897e1a | ||
![]() |
de5091d14d | ||
![]() |
db619bf5cd | ||
![]() |
ce76fe161e | ||
![]() |
6a8f6cc649 | ||
![]() |
84cad4820e | ||
![]() |
edd5185f49 | ||
![]() |
3c666a0d35 | ||
![]() |
0aa48e47e4 | ||
![]() |
9c8f4898a3 | ||
![]() |
57904fdc16 | ||
![]() |
916c0ce7ee | ||
![]() |
b969d84fcc | ||
![]() |
46f8aa7472 | ||
![]() |
065cf7833d | ||
![]() |
f4918697a9 | ||
![]() |
6a4b1aa8ce | ||
![]() |
e91821ec35 | ||
![]() |
7a52345fd3 | ||
![]() |
1aa92f2090 | ||
![]() |
704d065606 | ||
![]() |
8d786a0e6f | ||
![]() |
44c7a818e8 | ||
![]() |
11b2ce0087 | ||
![]() |
1c15d5cd45 | ||
![]() |
bda4c9bf2d | ||
![]() |
8e9667654f | ||
![]() |
5ca35ab5bc | ||
![]() |
562f968285 | ||
![]() |
eb169a95dd | ||
![]() |
613817fc4f | ||
![]() |
363c59f6cb | ||
![]() |
a5926a5179 | ||
![]() |
31786706d1 | ||
![]() |
14f15d8589 | ||
![]() |
8dc8b75c04 | ||
![]() |
4b3f10e0f5 | ||
![]() |
40c5e2ee3e | ||
![]() |
e088a3b2c0 | ||
![]() |
3b71c5b54c | ||
![]() |
16eac7eb20 | ||
![]() |
c015e6660c | ||
![]() |
62f062abed | ||
![]() |
e927ad9add | ||
![]() |
31e3916a0b | ||
![]() |
cb5c2ac773 | ||
![]() |
3a3d1ada89 |
1
.github/FUNDING.yml
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
github: [ m1k1o ]
|
58
.github/workflows/build.yml
vendored
Normal file
|
@ -0,0 +1,58 @@
|
|||
name: "CI for builds"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
env:
|
||||
IMAGE_NAME: m1k1o/blog
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
#
|
||||
# do not run on forks
|
||||
#
|
||||
if: github.repository_owner == 'm1k1o'
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
-
|
||||
name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
-
|
||||
name: Available platforms
|
||||
run: echo ${{ steps.buildx.outputs.platforms }}
|
||||
-
|
||||
name: Extract metadata (tags, labels) for Docker
|
||||
uses: docker/metadata-action@v3
|
||||
id: meta
|
||||
with:
|
||||
images: ${{ env.IMAGE_NAME }}
|
||||
tags: |
|
||||
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}
|
||||
type=semver,pattern={{version}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
type=semver,pattern={{major}}
|
||||
-
|
||||
name: Log in to the Container registry
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.DOCKER_TOKEN }}
|
||||
-
|
||||
name: Build and push
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||
push: true
|
9
.gitignore
vendored
|
@ -1,7 +1,10 @@
|
|||
# Custom config (legacy)
|
||||
custom.ini
|
||||
|
||||
# Ignore images & thumbnails directories (legacy)
|
||||
i/*
|
||||
!i/.gitkeep
|
||||
|
||||
t/*
|
||||
!t/.gitkeep
|
||||
|
||||
# Ignore all files in data but keep directory itself
|
||||
data/*
|
||||
!data/.gitkeep
|
||||
|
|
15
.htaccess
|
@ -1,4 +1,15 @@
|
|||
<Files ~ "\.(ini|log|sql)$">
|
||||
Options -Indexes
|
||||
|
||||
<Files ~ "\.(db|ini|sql|log|class\.php)$">
|
||||
Order Allow,Deny
|
||||
Deny from All
|
||||
</Files>
|
||||
</Files>
|
||||
|
||||
<Files ~ "^(\.|Dockerfile|docker-compose\.yml|README\.md)">
|
||||
Order Allow,Deny
|
||||
Deny from All
|
||||
</Files>
|
||||
|
||||
# Allow uploading large images
|
||||
php_value upload_max_filesize 32M
|
||||
php_value post_max_size 32M
|
||||
|
|
30
Dockerfile
Normal file
|
@ -0,0 +1,30 @@
|
|||
FROM php:7.4-apache
|
||||
|
||||
RUN set -eux; apt-get update; \
|
||||
apt-get install -y --no-install-recommends libpq-dev \
|
||||
#
|
||||
# install curl
|
||||
libcurl4-openssl-dev \
|
||||
#
|
||||
# install gd dependencies
|
||||
zlib1g-dev libpng-dev libjpeg-dev \
|
||||
libwebp-dev libxpm-dev libfreetype6-dev; \
|
||||
#
|
||||
# clean up
|
||||
rm -rf /var/lib/apt/lists/*; \
|
||||
#
|
||||
# configure extensions
|
||||
docker-php-ext-configure gd --enable-gd \
|
||||
--with-jpeg --with-webp --with-xpm --with-freetype; \
|
||||
#
|
||||
# install extensions
|
||||
docker-php-ext-install curl gd pdo pdo_mysql pdo_pgsql exif; \
|
||||
#
|
||||
# set up environment
|
||||
a2enmod rewrite;
|
||||
|
||||
#
|
||||
# copy files
|
||||
COPY --chown=33:33 . /var/www/html
|
||||
|
||||
VOLUME /var/www/html/data
|
674
LICENSE
Normal file
|
@ -0,0 +1,674 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
277
README.md
|
@ -1,9 +1,274 @@
|
|||
# blog
|
||||
This is a simple self-hosted, lightweight, singe-user PHP blog, where you can create your own Facebook-like feed. Give read access to other people, and you can share rich text with photos including highlighted code or links.
|
||||
|
||||
Requirements: Apache, PHP 7.0, MySQL
|
||||
In this context lightweight means:
|
||||
* No npm dependency, there won't be an annoying 1GB `node_modules` directory.
|
||||
* No pipeline. What you see is pure code without a need to install it.
|
||||
* No overhead, essential features, simple usage.
|
||||
|
||||
## How to install
|
||||
1. Copy files
|
||||
2. Import db.sql => MySQL
|
||||
3. Copy config.ini => custom.ini and define
|
||||
4. Done
|
||||
## Live demo
|
||||
Live demo is available here:
|
||||
|
||||
https://blog.m1k1o.net/
|
||||
|
||||
Please note, that this demo has very limited computing resources, strict rate limiting and can be reset at anytime. Upload of files will not always work, but as simple demo to see this product in action it is enough.
|
||||
|
||||
## Screenshots
|
||||
<details>
|
||||
<summary>Light theme</summary>
|
||||
|
||||

|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Dark theme</summary>
|
||||
|
||||

|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Legacy theme (compatible with older browsers)</summary>
|
||||
|
||||

|
||||
</details>
|
||||
|
||||
## Zero configuration setup
|
||||
Container will run without any initial configuration needed using SQLite as database provider. For better performance consider using MySQL.
|
||||
|
||||
```sh
|
||||
docker run -d -p 80:80 -v $PWD/data:/var/www/html/data m1k1o/blog:latest
|
||||
```
|
||||
|
||||
You can set environment variables, prefixed with `BLOG_` and uppercase. They can be found in `config.ini`.
|
||||
```sh
|
||||
docker run -d \
|
||||
-p 80:80 \
|
||||
-e "TZ=Europe/Vienna" \
|
||||
-e "BLOG_TITLE=Blog" \
|
||||
-e "BLOG_NAME=Max Musermann" \
|
||||
-e "BLOG_NICK=username" \
|
||||
-e "BLOG_PASS=password" \
|
||||
-e "BLOG_LANG=en" \
|
||||
-v $PWD/data:/var/www/html/data \
|
||||
m1k1o/blog:latest
|
||||
```
|
||||
|
||||
Or for docker-compose format, see [docker-compose.yml](docker-compose.yml).
|
||||
|
||||
## Install standalone app using `docker-compose` with external database
|
||||
You need to install [docker-compose](https://docs.docker.com/compose/install/).
|
||||
|
||||
### MySQL
|
||||
```yaml
|
||||
version: "3"
|
||||
services:
|
||||
webserver:
|
||||
image: m1k1o/blog:latest
|
||||
container_name: blog_apache
|
||||
environment:
|
||||
TZ: Europe/Vienna
|
||||
BLOG_DB_CONNECTION: mysql
|
||||
BLOG_MYSQL_HOST: mariadb
|
||||
BLOG_MYSQL_PORT: 3306
|
||||
BLOG_MYSQL_USER: blog
|
||||
BLOG_MYSQL_PASS: blog # use secure password
|
||||
BLOG_DB_NAME: blog
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- ${HTTP_PORT-80}:80
|
||||
volumes:
|
||||
- ${DATA-./data}:/var/www/html/data
|
||||
mariadb:
|
||||
image: mariadb:10.1
|
||||
container_name: blog_mariadb
|
||||
environment:
|
||||
MYSQL_USER: blog
|
||||
MYSQL_PASSWORD: blog # use secure password
|
||||
MYSQL_DATABASE: blog
|
||||
MYSQL_ROOT_PASSWORD: root # use secure password
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- mariadb:/var/lib/mysql
|
||||
- ./app/db/mysql:/docker-entrypoint-initdb.d:ro
|
||||
volumes:
|
||||
mariadb:
|
||||
```
|
||||
|
||||
### Postgres
|
||||
```yaml
|
||||
version: "3"
|
||||
services:
|
||||
webserver:
|
||||
image: m1k1o/blog:latest
|
||||
container_name: blog_apache
|
||||
environment:
|
||||
TZ: Europe/Vienna
|
||||
BLOG_DB_CONNECTION: postgres
|
||||
BLOG_POSTGRES_HOST: postgres
|
||||
BLOG_POSTGRES_PORT: 5432
|
||||
BLOG_POSTGRES_USER: blog
|
||||
BLOG_POSTGRES_PASS: blog # use secure password
|
||||
BLOG_DB_NAME: blog
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- ${HTTP_PORT-80}:80
|
||||
volumes:
|
||||
- ${DATA-./data}:/var/www/html/data
|
||||
postgres:
|
||||
image: postgres:14
|
||||
container_name: blog_postgres
|
||||
environment:
|
||||
POSTGRES_USER: blog
|
||||
POSTGRES_PASSWORD: blog # use secure password
|
||||
POSTGRES_DB: blog
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- postgres:/var/lib/postgresql/data
|
||||
- ./app/db/postgres:/docker-entrypoint-initdb.d:ro
|
||||
volumes:
|
||||
postgres:
|
||||
```
|
||||
|
||||
### Step 1: Run `docker-compose.yml`.
|
||||
Select one of configurations above and save it to `docker-compose.yml`. Then run:
|
||||
```sh
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
You can specify these environment variables, otherwise the default ones will be used:
|
||||
* **HTTP_PORT=80** - where the blog will be accessible.
|
||||
* **DATA=./data** - directory to store the user data.
|
||||
|
||||
These environment variables can be stored in the `.env` file or passed to the command directly:
|
||||
```sh
|
||||
HTTP_PORT=3001 DATA=/home/user/blog docker-compose up -d
|
||||
```
|
||||
|
||||
### Step 2: Create `data/` directory and download `config.ini` file.
|
||||
Download default config file and copy to your new `./data/` directory.
|
||||
|
||||
```sh
|
||||
mkdir data && cd data
|
||||
wget https://raw.githubusercontent.com/m1k1o/blog/master/config.ini
|
||||
```
|
||||
|
||||
Now you can modify your config. Or you can set environment variables, in uppercase, starting with `BLOG_`, e.g. `BLOG_NAME: Max's blog`.
|
||||
|
||||
### Correct permissions
|
||||
Make sure your `./data/` directory has correct permissions. Apache is running as a `www-data` user, which needs to have write access to the `./data/` directory (for uploading images).
|
||||
|
||||
#### Prefered solution
|
||||
Change the directory owner to the `www-data` user:
|
||||
|
||||
```sh
|
||||
chown 33:33 ./data/
|
||||
```
|
||||
|
||||
Alternatively, add the `www-data` user to the user group that owns the `./data/` directory.
|
||||
|
||||
#### Bad solution (but it works)
|
||||
Set `777` permission for your `./data/`, so everyone can read, write, and execute:
|
||||
|
||||
```sh
|
||||
chmod 777 ./data/
|
||||
```
|
||||
|
||||
**NOTICE:** You should not use `777`. You are giving access to anyone for this directory. Maybe to some attacker, who can run his exploit here.
|
||||
|
||||
## Install
|
||||
If you have decided that you don't want to use Docker, you can intall it manually.
|
||||
|
||||
**Requirements:** Apache 2.0*, PHP 7.4, (MariaDB 10.1 or SQLite 3)
|
||||
|
||||
**NOTICE:** If you would like to use Nginx or another web server, make sure that the sensitive data are not exposed to the public. Since `.htaccess` is protecting those files in Apache, that could not be the case in a different environment. Take care of:
|
||||
* **config.ini** - disallow access to all *.ini* files for the public.
|
||||
* **data/logs/\_ANY_.log** - make sure no sensitive information are located in *.log*.
|
||||
|
||||
### Database Schema
|
||||
You can find database schema in `./app/db` folder.
|
||||
|
||||
### Debug mode
|
||||
To check if your server is set up correctly, turn on a debug mode (in config add `debug = true`) to see the details. In the debug mode, an error may be shown if you are missing some **PHP extensions** needed to be installed on your server.
|
||||
|
||||
## Config file
|
||||
**DO NOT** edit `./config.ini` file. If you wish to modify the config, simply make a copy to the `./data/config.ini` directory and edit it there.
|
||||
|
||||
**But, why?** If there is any change in config file (most likely adding a new feature), you will have problems with merging a new version. Also, if you would fork this repository, you might accidentally push your secrets to the git. We don't want that to happen. Content of the `/data` directory is ignored by the git, so none of your pictures or personal data should ever be published to git.
|
||||
|
||||
# Features
|
||||
|
||||
* Dark mode, retina ready, legacy theme available.
|
||||
* Use BBcode in texts.
|
||||
* Make posts available for **everyone**, **only you** or just for **friends**.
|
||||
* Extra fields in post: **Feeling**, **With** and **At**.
|
||||
* Hide posts from timeline so they are visible only when you need them to be.
|
||||
* All pasted links will get preview with page title, description and image (can be configured proxy).
|
||||
* Upload images using button *(for mobile)*.
|
||||
* Upload images using drag & drop *(drop it into textarea)*.
|
||||
* Upload images using CTRL + V *(paste it into textarea)*.
|
||||
* Highlight code in post using `[code]..your code..[/code]`.
|
||||
* Highlight your goal using `[goal]Text of your goal.[/goal]`.
|
||||
* Use tags in posts (allowed characters `A-Za-z0-9-_` terminated by space or EOL): `#song`.
|
||||
* Sort posts in reverse order (oldest first): `http://blog/#sort=reverse`.
|
||||
* Filter posts by hashtags: `http://blog/#tag=songs`.
|
||||
* Filter posts by location in url using: `http://blog/#loc=Vienna`.
|
||||
* Display posts from chosen date using (format YYYY-MM-DD or YYY-MM): `http://blog/#from=2017-06`.
|
||||
* Display posts to chosen date using (format YYYY-MM-DD or YYY-MM): `http://blog/#to=2017-06`.
|
||||
* Combine parameters in url using `&`, e.g. show posts between dates: `http://blog/#from=2017-06&to=2017-08`.
|
||||
|
||||
## Access control
|
||||
|
||||
This blog is using Mandatory Access Control (MAC), with 3 types of access levels:
|
||||
|
||||
* **Private** posts are visible only to your single account specified in `nick` and `pass`.
|
||||
* You can specify group of your **friends** and share posts only for them.
|
||||
* **Public** posts are visible to everyone, without login.
|
||||
|
||||
In `docker-compose.yml` file, specify your credentials and friends like this:
|
||||
|
||||
```yml
|
||||
version: "3"
|
||||
services:
|
||||
blog:
|
||||
image: m1k1o/blog:latest
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
TZ: Europe/Vienna
|
||||
BLOG_NICK: admin_username
|
||||
BLOG_PASS: admin_password
|
||||
BLOG_FRIENDS: |
|
||||
jane:mysecretpass
|
||||
thomas:anotherpass
|
||||
ports:
|
||||
- 80:80
|
||||
volumes:
|
||||
- ./data:/var/www/html/data
|
||||
```
|
||||
|
||||
You can specify your credentials and friends in your `config.ini` file e.g.:
|
||||
|
||||
```ini
|
||||
[admin]
|
||||
force_login = true
|
||||
nick = admin_username
|
||||
pass = admin_password
|
||||
|
||||
[friends]
|
||||
friends[jane] = mysecretpass
|
||||
friends[thomas] = anotherpass
|
||||
```
|
||||
|
||||
## Localisation
|
||||
Timezone can be set in config or, for docker users, `TZ` environment variable is supported. List of timezones can be found [here](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
|
||||
|
||||
### Language support
|
||||
Feel free to create new PR and add a new language. Specify language in config or in url: `http://blog/?hl=sk`.
|
||||
|
||||
* en - 🇬🇧 English
|
||||
* de - 🇩🇪 German
|
||||
* sk - 🇸🇰 Slovak
|
||||
* fr - 🇫🇷 French (thanks @Phundrak)
|
||||
* cz - 🇨🇿 Czech (thanks @djfinch)
|
||||
* bs - 🇧🇦 Bosnian (thanks @hajro92)
|
||||
* es - 🇪🇸 Spanish (thanks @ManuLinares)
|
||||
* ru - 🇷🇺 Russian (thanks @ozzyst)
|
||||
|
|
10
ajax.php
|
@ -5,24 +5,24 @@ $ajax = new Ajax();
|
|||
|
||||
try {
|
||||
$ajax->token();
|
||||
|
||||
|
||||
// Prepare inputs
|
||||
$request = array_merge(@$_POST, @$_GET);
|
||||
if(empty($request["action"])){
|
||||
throw new Exception("No action specified.");
|
||||
}
|
||||
|
||||
|
||||
$method = ['Post', $request["action"]];
|
||||
|
||||
|
||||
// If method exists
|
||||
if(!is_callable($method)){
|
||||
throw new Exception("Method was not found.");
|
||||
}
|
||||
|
||||
|
||||
// CAll method
|
||||
$response = call_user_func($method, $request);
|
||||
$ajax->set_response($response);
|
||||
|
||||
|
||||
// Log
|
||||
Log::put("ajax_access", $request["action"]);
|
||||
} catch (Exception $e) {
|
||||
|
|
|
@ -1,40 +1,53 @@
|
|||
<?php
|
||||
defined('PROJECT_PATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Ajax
|
||||
{
|
||||
private $_response = null;
|
||||
|
||||
|
||||
public function __construct(){
|
||||
ob_start();
|
||||
}
|
||||
|
||||
public function set_error($msg = null){
|
||||
$this->_response = [
|
||||
"error" => true,
|
||||
"msg" => $msg
|
||||
];
|
||||
|
||||
|
||||
// Incldue debug info
|
||||
if(ob_get_length() > 0 && Config::get_safe('debug', false)){
|
||||
$this->_response["debug"] = ob_get_clean();
|
||||
}
|
||||
|
||||
// Log
|
||||
Log::put("ajax_errors", $msg);
|
||||
}
|
||||
|
||||
|
||||
public function token(){
|
||||
if(empty($_SESSION['token'])){
|
||||
throw new Exception("Direct access violation.");
|
||||
}
|
||||
|
||||
|
||||
$headers = apache_request_headers();
|
||||
if(!isset($headers['Csrf-Token']) || empty($_SESSION['token'])){
|
||||
if(!isset($headers['Csrf-Token']) && !isset($headers['csrf-token'])){
|
||||
throw new Exception("No CSRF token.");
|
||||
}
|
||||
|
||||
if($headers['Csrf-Token'] !== $_SESSION['token']){
|
||||
|
||||
if($headers['Csrf-Token'] !== $_SESSION['token'] && $headers['csrf-token'] !== $_SESSION['token']){
|
||||
throw new Exception("Wrong CSRF token.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function set_response($response = null){
|
||||
$this->_response = $response;
|
||||
}
|
||||
|
||||
|
||||
public function json_response(){
|
||||
ob_clean();
|
||||
if(ob_get_length() > 0) {
|
||||
ob_clean();
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($this->_response);
|
||||
}
|
118
app/config.class.php
Normal file
|
@ -0,0 +1,118 @@
|
|||
<?php
|
||||
defined('PROJECT_PATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Config
|
||||
{
|
||||
const CONFIG = 'config.ini';
|
||||
const CUSTOM = 'data/config.ini';
|
||||
const CUSTOM_FALLBACK = 'custom.ini';
|
||||
const ENV_PREFIX = 'BLOG_';
|
||||
|
||||
private static $_settings = null;
|
||||
|
||||
private static function init(){
|
||||
$config_file = PROJECT_PATH.self::CONFIG;
|
||||
if(!is_readable($config_file)){
|
||||
throw new ConfigException('Cannot read config file.');
|
||||
}
|
||||
|
||||
$default_settings = parse_ini_file($config_file);
|
||||
if($default_settings === false){
|
||||
throw new ConfigException('Cannot parse config file.');
|
||||
}
|
||||
|
||||
$custom_settings = [];
|
||||
if(is_readable($config_file = PROJECT_PATH.self::CUSTOM)){
|
||||
$custom = parse_ini_file($config_file);
|
||||
if($custom !== false){
|
||||
$custom_settings = $custom;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback for legacy versions
|
||||
elseif(is_readable($config_file = PROJECT_PATH.self::CUSTOM_FALLBACK)){
|
||||
$custom = parse_ini_file($config_file);
|
||||
if($custom !== false){
|
||||
// Fallback for old direcotry structure
|
||||
if(!array_key_exists('images_path', $custom) && !array_key_exists('thumbnails_path', $custom)){
|
||||
$custom['images_path'] = 'i/';
|
||||
$custom['thumbnails_path'] = 't/';
|
||||
}
|
||||
|
||||
$custom_settings = array_merge($custom_settings, $custom);
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback for versions, where mysql was default
|
||||
if(!array_key_exists('db_connection', $custom_settings) && array_key_exists('mysql_user', $custom_settings) &&
|
||||
(array_key_exists('mysql_socket', $custom_settings) || array_key_exists('mysql_host', $custom_settings))) {
|
||||
$custom_settings['db_connection'] = 'mysql';
|
||||
}
|
||||
|
||||
// Merge default and custom settings
|
||||
self::$_settings = array_merge($default_settings, $custom_settings);
|
||||
|
||||
// From envs
|
||||
$envs = getenv();
|
||||
$env_prefix_len = strlen(self::ENV_PREFIX);
|
||||
foreach($envs as $key => $value){
|
||||
if(substr($key, 0, $env_prefix_len) === self::ENV_PREFIX){
|
||||
$key = strtolower(substr($key, $env_prefix_len));
|
||||
|
||||
if($value === 'true'){
|
||||
$value = true;
|
||||
}
|
||||
elseif($value === 'false'){
|
||||
$value = false;
|
||||
}
|
||||
|
||||
// Associative arrays in environment variables
|
||||
if($key === 'visitor' || $key === 'friends'){
|
||||
$value = self::parse_env_assoc($value);
|
||||
}
|
||||
|
||||
self::$_settings[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function get($key){
|
||||
if(self::$_settings === null){
|
||||
self::init();
|
||||
}
|
||||
|
||||
if(!array_key_exists($key, self::$_settings)){
|
||||
throw new ConfigException(sprintf('Key "%s" not found in settings.', $key));
|
||||
}
|
||||
|
||||
return self::$_settings[$key];
|
||||
}
|
||||
|
||||
public static function get_safe($key, $default = ''){
|
||||
try {
|
||||
$value = self::get($key);
|
||||
} catch (ConfigException $e) {
|
||||
$value = $default;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
// Parse associative array from string in format key:value
|
||||
private static function parse_env_assoc($data){
|
||||
if(!preg_match_all("/([^\s]+):([^\s]+)/s", $data, $matches)){
|
||||
return [];
|
||||
}
|
||||
|
||||
list($_, $keys, $values) = $matches;
|
||||
|
||||
$array = [];
|
||||
foreach ($values as $key => $value) {
|
||||
$array[$keys[$key]] = $value;
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
|
||||
class ConfigException extends Exception {}
|
|
@ -1,78 +1,204 @@
|
|||
<?php
|
||||
defined('PROJECT_PATH') OR exit('No direct script access allowed');
|
||||
|
||||
// v3.43
|
||||
// v3.43 (+ query counter)
|
||||
class DB
|
||||
{
|
||||
private static $_instance = null;
|
||||
|
||||
|
||||
private $_PDO;
|
||||
private $_query;
|
||||
|
||||
|
||||
private $_query_counter;
|
||||
|
||||
// Handle instances
|
||||
public final static function get_instance(){
|
||||
if(self::$_instance == null){
|
||||
if(self::$_instance === null){
|
||||
self::$_instance = new static();
|
||||
}
|
||||
|
||||
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
|
||||
public static function connection() {
|
||||
return Config::get_safe('db_connection', 'sqlite');
|
||||
}
|
||||
|
||||
// CONCAT() does not exist in SQLite, using || instead
|
||||
// for postgres, ERROR: could not determine data type of parameter $1
|
||||
public final static function concat(){
|
||||
$values = func_get_args();
|
||||
|
||||
if(DB::connection() === 'sqlite' || DB::connection() === 'postgres') {
|
||||
return implode(" || ", $values);
|
||||
} else {
|
||||
return 'CONCAT('.implode(", ", $values).')';
|
||||
}
|
||||
}
|
||||
|
||||
// Initialise PDO object
|
||||
private final function __construct(){
|
||||
switch(DB::connection()) {
|
||||
case 'mysql':
|
||||
$this->mysql_connect();
|
||||
break;
|
||||
case 'postgres':
|
||||
$this->postgres_connect();
|
||||
break;
|
||||
case 'sqlite':
|
||||
$this->sqlite_connect();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private final function mysql_connect(){
|
||||
$host = Config::get_safe('mysql_host', false);
|
||||
$port = Config::get_safe('mysql_port', false);
|
||||
$socket = Config::get_safe('mysql_socket', false);
|
||||
|
||||
|
||||
if($socket === false && $host === false){
|
||||
throw new DBException("Mysql host or socket must be defined");
|
||||
throw new DBException("Mysql host or socket must be defined.");
|
||||
}
|
||||
|
||||
if($socket !== false){
|
||||
$server = 'unix_socket='.$socket;
|
||||
} else {
|
||||
$server = 'host='.$host;
|
||||
}
|
||||
|
||||
|
||||
// Try to connect
|
||||
try {
|
||||
$this->_PDO = new \PDO(
|
||||
// Server
|
||||
'mysql:'.$server.';'.
|
||||
'mysql:'.
|
||||
($socket !== false
|
||||
? 'unix_socket='.$socket
|
||||
: 'host='.$host.($port !== false ? ';port='.$port : '')
|
||||
).
|
||||
// DB
|
||||
'dbname='.Config::get('db_name').';'.
|
||||
';dbname='.Config::get('db_name').
|
||||
// Charset
|
||||
'charset=utf8',
|
||||
';charset=utf8',
|
||||
// Username
|
||||
Config::get('mysql_user'),
|
||||
// Password
|
||||
Config::get('mysql_pass', '')
|
||||
Config::get_safe('mysql_pass', ''),
|
||||
// Set attributes
|
||||
[
|
||||
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
|
||||
\PDO::ATTR_EMULATE_PREPARES => false
|
||||
]
|
||||
);
|
||||
$this->_PDO->exec('SET NAMES utf8');
|
||||
} catch (\PDOException $e) {
|
||||
|
||||
$this->_PDO->exec(
|
||||
// Set charset
|
||||
'SET NAMES utf8;'.
|
||||
|
||||
// Set timezone
|
||||
'SET time_zone="'.date('P').'";'
|
||||
);
|
||||
} catch (PDOException $e) {
|
||||
throw new DBException($e->getMessage());
|
||||
}
|
||||
|
||||
// When is this not set, chat does dot work, odd behavior
|
||||
$this->_PDO->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
|
||||
|
||||
// Throwing exceptions
|
||||
$this->_PDO->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||
//$this->_PDO->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
|
||||
}
|
||||
|
||||
|
||||
private final function postgres_connect(){
|
||||
$host = Config::get_safe('postgres_host', false);
|
||||
$port = Config::get_safe('postgres_port', false);
|
||||
$socket = Config::get_safe('postgres_socket', false);
|
||||
|
||||
if($socket === false && $host === false){
|
||||
throw new DBException("Postgres host or socket must be defined.");
|
||||
}
|
||||
|
||||
// Try to connect
|
||||
try {
|
||||
$this->_PDO = new \PDO(
|
||||
// Server
|
||||
'pgsql:'.
|
||||
($socket !== false
|
||||
? 'unix_socket='.$socket
|
||||
: 'host='.$host.($port !== false ? ';port='.$port : '')
|
||||
).
|
||||
// DB
|
||||
';dbname='.Config::get('db_name').
|
||||
// Charset
|
||||
';options=\'--client_encoding=UTF8\'',
|
||||
// Username
|
||||
Config::get('postgres_user'),
|
||||
// Password
|
||||
Config::get_safe('postgres_pass', ''),
|
||||
// Set attributes
|
||||
[
|
||||
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
|
||||
\PDO::ATTR_EMULATE_PREPARES => false
|
||||
]
|
||||
);
|
||||
|
||||
$this->_PDO->exec(
|
||||
// Set timezone
|
||||
'SET TIME ZONE "'.date('e').'";'
|
||||
);
|
||||
} catch (PDOException $e) {
|
||||
throw new DBException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private final function sqlite_connect(){
|
||||
$sqlite_db = PROJECT_PATH.Config::get_safe('sqlite_db', "data/sqlite.db");
|
||||
|
||||
// First run of sqlite
|
||||
if(!file_exists($sqlite_db)) {
|
||||
if(!is_writable(dirname($sqlite_db))) {
|
||||
throw new DBException("Sqlite database directory must me writable.");
|
||||
}
|
||||
|
||||
if(!touch($sqlite_db)) {
|
||||
throw new DBException("Cannot create sqlite database file.");
|
||||
}
|
||||
|
||||
// Inilialize SQL schema
|
||||
$sql_schema = file_get_contents(APP_PATH."db/sqlite/01_schema.sql");
|
||||
|
||||
try {
|
||||
$this->_PDO = new \PDO("sqlite:".$sqlite_db, null, null, [
|
||||
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION
|
||||
]);
|
||||
$this->_PDO->exec($sql_schema);
|
||||
} catch (PDOException $e) {
|
||||
$this->_PDO = null;
|
||||
unlink($sqlite_db);
|
||||
|
||||
throw new DBException($e->getMessage());
|
||||
}
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
// Try to connect
|
||||
try {
|
||||
$this->_PDO = new \PDO("sqlite:".$sqlite_db, null, null, [
|
||||
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION
|
||||
]);
|
||||
} catch (PDOException $e) {
|
||||
throw new DBException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Just flattern array to be binded : [key1, key2, [key3, [key4]]] => [key1, key2, key3, key4]
|
||||
private final function bind_value($key, $value){
|
||||
if(is_array($value)){
|
||||
foreach($value as $one_value){
|
||||
$key = $this->bind_value($key, $one_value);
|
||||
}
|
||||
|
||||
|
||||
return $key;
|
||||
}
|
||||
|
||||
|
||||
// BUG: Force strings to be UTF-8
|
||||
// remove all 4-bytes characters.
|
||||
if(is_string($value)){
|
||||
$value = preg_replace('/[\xF0-\xF7].../s', '', $value);
|
||||
}
|
||||
|
||||
$this->_query->bindValue($key, $value);
|
||||
return ++$key;
|
||||
}
|
||||
|
||||
|
||||
// Process Query
|
||||
// query ($sql)
|
||||
// query ($sql, $bind_param_01, $bind_param_02, ...)
|
||||
|
@ -80,53 +206,54 @@ class DB
|
|||
public final function query(){
|
||||
// Second parm is binded values
|
||||
$params = func_get_args();
|
||||
|
||||
|
||||
// First parameter is sql
|
||||
$sql = $params[0];
|
||||
unset($params[0]);
|
||||
|
||||
|
||||
// Replace backticks with " for postgres
|
||||
if(DB::connection() === 'postgres') {
|
||||
$sql = str_replace("`", '"', $sql);
|
||||
}
|
||||
|
||||
// Debug mode
|
||||
if(Config::get_safe('debug', false)){
|
||||
echo "<!-- ".$sql." + ".json_encode($params)." -->\n";
|
||||
}
|
||||
|
||||
|
||||
// Try to prepare MySQL statement
|
||||
try {
|
||||
// Prepare PDO statement
|
||||
$this->_query = $this->_PDO->prepare($sql);
|
||||
|
||||
|
||||
// Bind values
|
||||
$this->bind_value(1, $params);
|
||||
|
||||
|
||||
// Execute
|
||||
$this->_query->execute();
|
||||
} catch (\PDOException $e) {
|
||||
} catch (PDOException $e) {
|
||||
throw new DBException($e->getMessage());
|
||||
}
|
||||
|
||||
// Debug mode
|
||||
//if(Config::get_safe('debug', false)){
|
||||
// echo "<!-- ".$this->_query->queryString." + ".json_encode($params)." -->\n";
|
||||
//}
|
||||
|
||||
|
||||
$this->_query_counter++;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
// Insert into table
|
||||
public final function insert($table_name, $fields = null){
|
||||
// If empty line
|
||||
if(empty($fields)){
|
||||
return $this->query("INSERT INTO `{$table_name}` () VALUES ()");
|
||||
}
|
||||
|
||||
|
||||
// If multiple
|
||||
if(isset($fields[0])){
|
||||
// Turn array into PDO prepered statement format
|
||||
$keys = array_keys($fields[0]);
|
||||
|
||||
|
||||
// Build query
|
||||
$query = "INSERT INTO `{$table_name}` (`".implode('`, `', $keys)."`) VALUES ";
|
||||
|
||||
|
||||
// Insert values
|
||||
$first = true;
|
||||
$prepared_data = array();
|
||||
|
@ -136,34 +263,38 @@ class DB
|
|||
} else {
|
||||
$query .= ',';
|
||||
}
|
||||
|
||||
|
||||
end($field);
|
||||
$last_key = key($field);
|
||||
|
||||
|
||||
$query .= '(';
|
||||
foreach($field as $key => $value){
|
||||
if($value === "NOW()"){
|
||||
$query .= 'NOW()';
|
||||
if(DB::connection() === 'sqlite') {
|
||||
$query .= "datetime('now', 'localtime')";
|
||||
} else {
|
||||
$query .= "NOW()";
|
||||
}
|
||||
} else {
|
||||
$query .= '?';
|
||||
$prepared_data[] = $value;
|
||||
}
|
||||
|
||||
|
||||
if($last_key != $key){
|
||||
$query .= ',';
|
||||
}
|
||||
}
|
||||
$query .= ')';
|
||||
}
|
||||
|
||||
|
||||
// Execute query
|
||||
return $this->query($query, $prepared_data);
|
||||
}
|
||||
|
||||
|
||||
// If only single
|
||||
return $this->insert($table_name, array($fields));
|
||||
}
|
||||
|
||||
|
||||
// Update table
|
||||
// update ($table_name, $fields)
|
||||
// update ($table_name, $fields, $sql)
|
||||
|
@ -172,101 +303,110 @@ class DB
|
|||
public final function update(){
|
||||
// Fourt param is binded values
|
||||
$params = func_get_args();
|
||||
|
||||
|
||||
// First is table_name
|
||||
$table_name = $params[0];
|
||||
unset($params[0]);
|
||||
|
||||
|
||||
// Second is fields
|
||||
$fields = $params[1];
|
||||
unset($params[1]);
|
||||
|
||||
|
||||
// Third is sql
|
||||
$sql = $params[2];
|
||||
unset($params[2]);
|
||||
|
||||
|
||||
// If fields are not array, do nothing
|
||||
if(!is_array($fields)){
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
end($fields);
|
||||
$last_key = key($fields);
|
||||
|
||||
|
||||
// Support for NOW()
|
||||
$prepared_data = array();
|
||||
$set_data = null;
|
||||
foreach($fields as $key => $value){
|
||||
if($value === "NOW()"){
|
||||
$set_data .="`{$key}` = NOW()";
|
||||
if(DB::connection() === 'sqlite') {
|
||||
$set_data .="`{$key}` = datetime('now', 'localtime')";
|
||||
} else {
|
||||
$set_data .="`{$key}` = NOW()";
|
||||
}
|
||||
} else {
|
||||
$set_data .= "`{$key}` = ?";
|
||||
$prepared_data[] = $value;
|
||||
}
|
||||
|
||||
|
||||
if($last_key != $key){
|
||||
$set_data .= ',';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// If params are not array, make it
|
||||
if(!is_array($params)){
|
||||
$params = array($params);
|
||||
}
|
||||
|
||||
|
||||
// Merge fields array and additional SQL data
|
||||
foreach($params as $param){
|
||||
$prepared_data[] = $param;
|
||||
}
|
||||
|
||||
|
||||
// Build query
|
||||
$query = "UPDATE `{$table_name}` SET {$set_data} ".$sql;
|
||||
|
||||
|
||||
// Execute query
|
||||
return $this->query($query, $prepared_data);
|
||||
}
|
||||
|
||||
|
||||
// Alias for all
|
||||
public final function results(){
|
||||
trigger_error("Using deprecated method <strong>DB::results();</strong>. Use <strong>DB::all();</strong> instead.");
|
||||
return $this->all();
|
||||
}
|
||||
|
||||
|
||||
// Get all rows
|
||||
public final function all($type = \PDO::FETCH_ASSOC){
|
||||
return $this->_query->fetchAll($type);
|
||||
}
|
||||
|
||||
|
||||
// Get all values to one dimensional array
|
||||
public final function columns($column = 0){
|
||||
return $this->_query->fetchAll(\PDO::FETCH_COLUMN, $column);
|
||||
}
|
||||
|
||||
|
||||
// Get first row from result
|
||||
public final function first($key = null){
|
||||
$results = $this->all();
|
||||
|
||||
|
||||
if($key !== null){
|
||||
return @$results[0][$key];
|
||||
}
|
||||
|
||||
|
||||
return @$results[0];
|
||||
}
|
||||
|
||||
|
||||
// Get last inserted ID
|
||||
public final function last_id(){
|
||||
return $this->_PDO->lastInsertId();
|
||||
}
|
||||
|
||||
|
||||
// Exec
|
||||
public final function exec($sql){
|
||||
// Try to execute MySQL
|
||||
try {
|
||||
$this->_PDO->exec($sql);
|
||||
return $this;
|
||||
} catch (\PDOException $e) {
|
||||
} catch (PDOException $e) {
|
||||
throw new DBException($e->getMessage());
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public final function total_queries(){
|
||||
return $this->_query_counter;
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ CREATE TABLE `posts` (
|
|||
`location` varchar(255) NOT NULL,
|
||||
`content` varchar(1000) NOT NULL,
|
||||
`content_type` varchar(255) NOT NULL,
|
||||
`pirvacy` set('private','friends','public') NOT NULL,
|
||||
`privacy` set('private','friends','public') NOT NULL,
|
||||
`datetime` datetime NOT NULL,
|
||||
`status` int(11) NOT NULL
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
26
app/db/postgres/01_schema.sql
Normal file
|
@ -0,0 +1,26 @@
|
|||
CREATE TABLE images (
|
||||
"id" serial PRIMARY KEY,
|
||||
"name" varchar(255) NOT NULL,
|
||||
"path" varchar(255) DEFAULT NULL,
|
||||
"thumb" varchar(255) DEFAULT NULL,
|
||||
"type" varchar(10) NOT NULL,
|
||||
"md5" char(32) NOT NULL,
|
||||
"datetime" timestamp NOT NULL,
|
||||
"status" int NOT NULL
|
||||
);
|
||||
|
||||
CREATE TYPE privacy_t as enum('private','friends','public');
|
||||
|
||||
CREATE TABLE posts (
|
||||
"id" serial PRIMARY KEY,
|
||||
"text" text NOT NULL,
|
||||
"plain_text" text NOT NULL,
|
||||
"feeling" varchar(255) NOT NULL,
|
||||
"persons" varchar(255) NOT NULL,
|
||||
"location" varchar(255) NOT NULL,
|
||||
"content" varchar(1000) NOT NULL,
|
||||
"content_type" varchar(255) NOT NULL,
|
||||
"privacy" privacy_t NOT NULL,
|
||||
"datetime" timestamp NOT NULL,
|
||||
"status" int NOT NULL
|
||||
);
|
24
app/db/sqlite/01_schema.sql
Normal file
|
@ -0,0 +1,24 @@
|
|||
CREATE TABLE `images` (
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`name` TEXT NOT NULL,
|
||||
`path` TEXT DEFAULT NULL,
|
||||
`thumb` TEXT DEFAULT NULL,
|
||||
`type` TEXT NOT NULL,
|
||||
`md5` TEXT NOT NULL,
|
||||
`datetime` INTEGER NOT NULL,
|
||||
`status` INTEGER NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE `posts` (
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`text` TEXT NOT NULL,
|
||||
`plain_text` TEXT NOT NULL,
|
||||
`feeling` TEXT NOT NULL,
|
||||
`persons` TEXT NOT NULL,
|
||||
`location` TEXT NOT NULL,
|
||||
`content` TEXT NOT NULL,
|
||||
`content_type` TEXT NOT NULL,
|
||||
`privacy` TEXT NOT NULL,
|
||||
`datetime` INTEGER NOT NULL,
|
||||
`status` INTEGER NOT NULL
|
||||
);
|
190
app/image.class.php
Normal file
|
@ -0,0 +1,190 @@
|
|||
<?php
|
||||
defined('PROJECT_PATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Image
|
||||
{
|
||||
const THUMB_W = 476;
|
||||
const THUMB_H = 476;
|
||||
|
||||
const PHP_FILE_UPLOAD_ERRORS = [
|
||||
0 => 'There is no error, the file uploaded with success.',
|
||||
1 => 'The uploaded file exceeds the upload_max_filesize directive in php.ini.',
|
||||
2 => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.',
|
||||
3 => 'The uploaded file was only partially uploaded.',
|
||||
4 => 'No file was uploaded.',
|
||||
6 => 'Missing a temporary folder.',
|
||||
7 => 'Failed to write file to disk.',
|
||||
8 => 'A PHP extension stopped the file upload.',
|
||||
];
|
||||
|
||||
private static function random_str($len = 10){
|
||||
$chr = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
||||
$chr_len = strlen($chr);
|
||||
$random_str = '';
|
||||
|
||||
for($i = 0; $i < $len; $i++){
|
||||
$random_str .= $chr[rand(0, $chr_len - 1)];
|
||||
}
|
||||
|
||||
return $random_str;
|
||||
}
|
||||
|
||||
private static function fix_orientation($path, $img){
|
||||
if(!function_exists('exif_read_data')){
|
||||
return $img;
|
||||
}
|
||||
|
||||
$exif = exif_read_data($path);
|
||||
if(!$exif || !isset($exif['Orientation'])){
|
||||
return $img;
|
||||
}
|
||||
|
||||
$deg = 0;
|
||||
switch($exif['Orientation']){
|
||||
case 3:
|
||||
$deg = 180;
|
||||
break;
|
||||
case 6:
|
||||
$deg = 270;
|
||||
break;
|
||||
case 8:
|
||||
$deg = 90;
|
||||
break;
|
||||
}
|
||||
|
||||
if($deg){
|
||||
return imagerotate($img, $deg, 0);
|
||||
}
|
||||
|
||||
return $img;
|
||||
}
|
||||
|
||||
private static function thumb($source_path, $thumb_path){
|
||||
ini_set('memory_limit', '128M');
|
||||
|
||||
$source_details = getimagesize($source_path);
|
||||
$source_w = $source_details[0];
|
||||
$source_h = $source_details[1];
|
||||
|
||||
if($source_w > $source_h){
|
||||
$new_w = self::THUMB_W;
|
||||
$new_h = intval($source_h * $new_w / $source_w);
|
||||
} else {
|
||||
$new_h = self::THUMB_H;
|
||||
$new_w = intval($source_w * $new_h / $source_h);
|
||||
}
|
||||
|
||||
switch($source_details[2]){
|
||||
case IMAGETYPE_GIF:
|
||||
$imgt = "imagegif";
|
||||
$imgcreatefrom = "imagecreatefromgif";
|
||||
break;
|
||||
|
||||
case IMAGETYPE_JPEG:
|
||||
$imgt = "imagejpeg";
|
||||
$imgcreatefrom = "imagecreatefromjpeg";
|
||||
break;
|
||||
|
||||
case IMAGETYPE_PNG:
|
||||
$imgt = "imagepng";
|
||||
$imgcreatefrom = "imagecreatefrompng";
|
||||
break;
|
||||
|
||||
case IMAGETYPE_WEBP:
|
||||
$imgt = "imagewebp";
|
||||
$imgcreatefrom = "imagecreatefromwebp";
|
||||
break;
|
||||
|
||||
case IMAGETYPE_WBMP:
|
||||
$imgt = "imagewbmp";
|
||||
$imgcreatefrom = "imagecreatefromwbmp";
|
||||
break;
|
||||
|
||||
case IMAGETYPE_BMP:
|
||||
$imgt = "imagebmp";
|
||||
$imgcreatefrom = "imagecreatefrombmp";
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
$old_image = $imgcreatefrom($source_path);
|
||||
if ($old_image === false) return false;
|
||||
|
||||
$new_image = imagecreatetruecolor($new_w, $new_h);
|
||||
imagecopyresampled($new_image, $old_image, 0, 0, 0, 0, $new_w, $new_h, $source_w, $source_h);
|
||||
|
||||
$new_image = self::fix_orientation($source_path, $new_image);
|
||||
$old_image = self::fix_orientation($source_path, $old_image);
|
||||
|
||||
return $imgt($new_image, $thumb_path)
|
||||
&& $imgt($old_image, $source_path);
|
||||
}
|
||||
|
||||
public static function upload(){
|
||||
if(!$_FILES){
|
||||
throw new Exception("No file.");
|
||||
}
|
||||
|
||||
// Create MD5
|
||||
$md5 = md5_file($_FILES['file']['tmp_name']);
|
||||
|
||||
// Find duplicate
|
||||
if($d = DB::get_instance()->query("SELECT `path`, `thumb` FROM `images` WHERE `md5` = ? AND `status` = 1 LIMIT 1", $md5)->first()){
|
||||
return $d;
|
||||
}
|
||||
|
||||
// Ensure, that directories exists
|
||||
$_images_path = Config::get('images_path');
|
||||
$_thumbnails_path = Config::get('thumbnails_path');
|
||||
if(
|
||||
(!is_dir($_images_path) && !mkdir($_images_path, 0755, true)) ||
|
||||
(!is_dir($_thumbnails_path) && !mkdir($_thumbnails_path, 0755, true))
|
||||
){
|
||||
throw new Exception("Images or thumbnails directory could not be created.");
|
||||
}
|
||||
|
||||
// Get metadata
|
||||
$name = $_FILES['file']['name'];
|
||||
$ext = pathinfo($name, PATHINFO_EXTENSION);
|
||||
|
||||
// Save to DB
|
||||
$id = DB::get_instance()->insert('images', [
|
||||
'name' => $name,
|
||||
'type' => $ext,
|
||||
'md5' => $md5,
|
||||
'datetime' => 'NOW()',
|
||||
'status' => 0,
|
||||
])->last_id();
|
||||
|
||||
// Create path name
|
||||
$name = dechex($id).self::random_str(3).".".$ext;
|
||||
$path = $_images_path.$name;
|
||||
$thumb = $_thumbnails_path.$name;
|
||||
|
||||
// Save path
|
||||
if(!move_uploaded_file($_FILES['file']['tmp_name'], $path)){
|
||||
throw new Exception(self::PHP_FILE_UPLOAD_ERRORS[$_FILES['file']['error']]);
|
||||
}
|
||||
|
||||
// Create thumb
|
||||
if(!self::thumb($path, $thumb)){
|
||||
unlink($path);
|
||||
unlink($thumb);
|
||||
throw new Exception("File is not valid image.");
|
||||
}
|
||||
|
||||
// Save to DB
|
||||
DB::get_instance()->update('images', [
|
||||
'path' => $path,
|
||||
'thumb' => $thumb,
|
||||
'status' => 1,
|
||||
], "WHERE `id` = ?", $id);
|
||||
|
||||
return [
|
||||
"path" => $path,
|
||||
"thumb" => $thumb
|
||||
];
|
||||
}
|
||||
}
|
329
app/jbbcode/codedefinition.class.php
Normal file
|
@ -0,0 +1,329 @@
|
|||
<?php
|
||||
namespace JBBCode;
|
||||
|
||||
defined('PROJECT_PATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* This class represents a BBCode Definition. You may construct instances of this class directly,
|
||||
* usually through the CodeDefinitionBuilder class, to create text replacement bbcodes, or you
|
||||
* may subclass it to create more complex bbcode definitions.
|
||||
*
|
||||
* @author jbowens
|
||||
*/
|
||||
class CodeDefinition
|
||||
{
|
||||
/* NOTE: THIS PROPERTY SHOULD ALWAYS BE LOWERCASE; USE setTagName() TO ENSURE THIS */
|
||||
protected $tagName;
|
||||
|
||||
/* Whether or not this CodeDefinition uses an option parameter. */
|
||||
protected $useOption;
|
||||
|
||||
/* The replacement text to be used for simple CodeDefinitions */
|
||||
protected $replacementText;
|
||||
|
||||
/* Whether or not to parse elements of this definition's contents */
|
||||
protected $parseContent;
|
||||
|
||||
/* How many of this element type may be nested within each other */
|
||||
protected $nestLimit;
|
||||
|
||||
/* How many of this element type have been seen */
|
||||
protected $elCounter;
|
||||
|
||||
/* The input validator to run options through */
|
||||
protected $optionValidator;
|
||||
|
||||
/* The input validator to run the body ({param}) through */
|
||||
protected $bodyValidator;
|
||||
|
||||
/**
|
||||
* Constructs a new CodeDefinition.
|
||||
*/
|
||||
public static function construct($tagName, $replacementText, $useOption = false,
|
||||
$parseContent = true, $nestLimit = -1, $optionValidator = array(),
|
||||
$bodyValidator = null)
|
||||
{
|
||||
$def = new CodeDefinition();
|
||||
$def->elCounter = 0;
|
||||
$def->setTagName($tagName);
|
||||
$def->setReplacementText($replacementText);
|
||||
$def->useOption = $useOption;
|
||||
$def->parseContent = $parseContent;
|
||||
$def->nestLimit = $nestLimit;
|
||||
$def->optionValidator = $optionValidator;
|
||||
$def->bodyValidator = $bodyValidator;
|
||||
return $def;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new CodeDefinition.
|
||||
*
|
||||
* This constructor is deprecated. You should use the static construct() method or the
|
||||
* CodeDefinitionBuilder class to construct a new CodeDefiniton.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
/* WARNING: This function is deprecated and will be made protected in a future
|
||||
* version of jBBCode. */
|
||||
$this->parseContent = true;
|
||||
$this->useOption = false;
|
||||
$this->nestLimit = -1;
|
||||
$this->elCounter = 0;
|
||||
$this->optionValidator = array();
|
||||
$this->bodyValidator = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the arguments to the given element are valid based on
|
||||
* any validators attached to this CodeDefinition.
|
||||
*
|
||||
* @param $el the ElementNode to validate
|
||||
* @return true if the ElementNode's {option} and {param} are OK, false if they're not
|
||||
*/
|
||||
public function hasValidInputs(ElementNode $el)
|
||||
{
|
||||
if ($this->usesOption() && $this->optionValidator) {
|
||||
$att = $el->getAttribute();
|
||||
|
||||
foreach($att as $name => $value){
|
||||
if(isset($this->optionValidator[$name]) && !$this->optionValidator[$name]->validate($value)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->parseContent() && $this->bodyValidator) {
|
||||
/* We only evaluate the content if we're not parsing the content. */
|
||||
$content = "";
|
||||
foreach ($el->getChildren() as $child) {
|
||||
$content .= $child->getAsBBCode();
|
||||
}
|
||||
if (!$this->bodyValidator->validate($content)) {
|
||||
/* The content of the element is not valid. */
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts an ElementNode that is defined by this CodeDefinition and returns the HTML
|
||||
* markup of the element. This is a commonly overridden class for custom CodeDefinitions
|
||||
* so that the content can be directly manipulated.
|
||||
*
|
||||
* @param $el the element to return an html representation of
|
||||
*
|
||||
* @return the parsed html of this element (INCLUDING ITS CHILDREN)
|
||||
*/
|
||||
public function asHtml(ElementNode $el)
|
||||
{
|
||||
if (!$this->hasValidInputs($el)) {
|
||||
return $el->getAsBBCode();
|
||||
}
|
||||
|
||||
$html = $this->getReplacementText();
|
||||
|
||||
if ($this->usesOption()) {
|
||||
$options = $el->getAttribute();
|
||||
if(count($options)==1){
|
||||
$vals = array_values($options);
|
||||
$html = str_ireplace('{option}', reset($vals), $html);
|
||||
}
|
||||
else{
|
||||
foreach($options as $key => $val){
|
||||
$html = str_ireplace('{' . $key . '}', $val, $html);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$content = $this->getContent($el);
|
||||
|
||||
$html = str_ireplace('{param}', $content, $html);
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
protected function getContent(ElementNode $el){
|
||||
if ($this->parseContent()) {
|
||||
$content = "";
|
||||
foreach ($el->getChildren() as $child)
|
||||
$content .= $child->getAsHTML();
|
||||
} else {
|
||||
$content = "";
|
||||
foreach ($el->getChildren() as $child)
|
||||
$content .= $child->getAsBBCode();
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts an ElementNode that is defined by this CodeDefinition and returns the text
|
||||
* representation of the element. This may be overridden by a custom CodeDefinition.
|
||||
*
|
||||
* @param $el the element to return a text representation of
|
||||
*
|
||||
* @return the text representation of $el
|
||||
*/
|
||||
public function asText(ElementNode $el)
|
||||
{
|
||||
if (!$this->hasValidInputs($el)) {
|
||||
return $el->getAsBBCode();
|
||||
}
|
||||
|
||||
$s = "";
|
||||
foreach ($el->getChildren() as $child)
|
||||
$s .= $child->getAsText();
|
||||
return $s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tag name of this code definition
|
||||
*
|
||||
* @return this definition's associated tag name
|
||||
*/
|
||||
public function getTagName()
|
||||
{
|
||||
return $this->tagName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the replacement text of this code definition. This usually has little, if any meaning if the
|
||||
* CodeDefinition class was extended. For default, html replacement CodeDefinitions this returns the html
|
||||
* markup for the definition.
|
||||
*
|
||||
* @return the replacement text of this CodeDefinition
|
||||
*/
|
||||
public function getReplacementText()
|
||||
{
|
||||
return $this->replacementText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not this CodeDefinition uses the optional {option}
|
||||
*
|
||||
* @return true if this CodeDefinition uses the option, false otherwise
|
||||
*/
|
||||
public function usesOption()
|
||||
{
|
||||
return $this->useOption;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not this CodeDefnition parses elements contained within it,
|
||||
* or just treats its children as text.
|
||||
*
|
||||
* @return true if this CodeDefinition parses elements contained within itself
|
||||
*/
|
||||
public function parseContent()
|
||||
{
|
||||
return $this->parseContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the limit of how many elements defined by this CodeDefinition may be
|
||||
* nested together. If after parsing elements are nested beyond this limit, the
|
||||
* subtrees formed by those nodes will be removed from the parse tree. A nest
|
||||
* limit of -1 signifies no limit.
|
||||
*/
|
||||
public function getNestLimit()
|
||||
{
|
||||
return $this->nestLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the tag name of this CodeDefinition
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @param the new tag name of this definition
|
||||
*/
|
||||
public function setTagName($tagName)
|
||||
{
|
||||
$this->tagName = strtolower($tagName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the html replacement text of this CodeDefinition
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @param the new replacement text
|
||||
*/
|
||||
public function setReplacementText($txt)
|
||||
{
|
||||
$this->replacementText = $txt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether or not this CodeDefinition uses the {option}
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @param boolean $bool
|
||||
*/
|
||||
public function setUseOption($bool)
|
||||
{
|
||||
$this->useOption = $bool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether or not this CodeDefinition allows its children to be parsed as html
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @param boolean $bool
|
||||
*/
|
||||
public function setParseContent($bool)
|
||||
{
|
||||
$this->parseContent = $bool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increments the element counter. This is used for tracking depth of elements of the same type for next limits.
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function incrementCounter()
|
||||
{
|
||||
$this->elCounter++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrements the element counter.
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function decrementCounter()
|
||||
{
|
||||
$this->elCounter--;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the element counter.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public function resetCounter()
|
||||
{
|
||||
$this->elCounter = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current value of the element counter.
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getCounter()
|
||||
{
|
||||
return $this->elCounter;
|
||||
}
|
||||
}
|
158
app/jbbcode/codedefinitionbuilder.class.php
Normal file
|
@ -0,0 +1,158 @@
|
|||
<?php
|
||||
namespace JBBCode;
|
||||
|
||||
defined('PROJECT_PATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Implements the builder pattern for the CodeDefinition class. A builder
|
||||
* is the recommended way of constructing CodeDefinition objects.
|
||||
*
|
||||
* @author jbowens
|
||||
*/
|
||||
class CodeDefinitionBuilder
|
||||
{
|
||||
|
||||
protected $tagName;
|
||||
protected $useOption = false;
|
||||
protected $replacementText;
|
||||
protected $parseContent = true;
|
||||
protected $nestLimit = -1;
|
||||
protected $optionValidator = array();
|
||||
protected $bodyValidator = null;
|
||||
|
||||
/**
|
||||
* Construct a CodeDefinitionBuilder.
|
||||
*
|
||||
* @param $tagName the tag name of the definition to build
|
||||
* @param $replacementText the replacement text of the definition to build
|
||||
*/
|
||||
public function __construct($tagName, $replacementText)
|
||||
{
|
||||
$this->tagName = $tagName;
|
||||
$this->replacementText = $replacementText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the tag name the CodeDefinition should be built with.
|
||||
*
|
||||
* @param $tagName the tag name for the new CodeDefinition
|
||||
*/
|
||||
public function setTagName($tagName)
|
||||
{
|
||||
$this->tagName = $tagName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the replacement text that the new CodeDefinition should be
|
||||
* built with.
|
||||
*
|
||||
* @param $replacementText the replacement text for the new CodeDefinition
|
||||
*/
|
||||
public function setReplacementText($replacementText)
|
||||
{
|
||||
$this->replacementText = $replacementText;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether or not the built CodeDefinition should use the {option} bbcode
|
||||
* argument.
|
||||
*
|
||||
* @param $option ture iff the definition includes an option
|
||||
*/
|
||||
public function setUseOption($option)
|
||||
{
|
||||
$this->useOption = $option;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether or not the built CodeDefinition should allow its content
|
||||
* to be parsed and evaluated as bbcode.
|
||||
*
|
||||
* @param $parseContent true iff the content should be parsed
|
||||
*/
|
||||
public function setParseContent($parseContent)
|
||||
{
|
||||
$this->parseContent = $parseContent;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the nest limit for this code definition.
|
||||
*
|
||||
* @param $nestLimit a positive integer, or -1 if there is no limit.
|
||||
* @throws \InvalidArgumentException if the nest limit is invalid
|
||||
*/
|
||||
public function setNestLimit($limit)
|
||||
{
|
||||
if(!is_int($limit) || ($limit <= 0 && -1 != $limit)) {
|
||||
throw new \InvalidArgumentException("A nest limit must be a positive integer " .
|
||||
"or -1.");
|
||||
}
|
||||
$this->nestLimit = $limit;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the InputValidator that option arguments should be validated with.
|
||||
*
|
||||
* @param $validator the InputValidator instance to use
|
||||
*/
|
||||
public function setOptionValidator(\JBBCode\InputValidator $validator, $option=null)
|
||||
{
|
||||
if(empty($option)){
|
||||
$option = $this->tagName;
|
||||
}
|
||||
$this->optionValidator[$option] = $validator;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the InputValidator that body ({param}) text should be validated with.
|
||||
*
|
||||
* @param $validator the InputValidator instance to use
|
||||
*/
|
||||
public function setBodyValidator(\JBBCode\InputValidator $validator)
|
||||
{
|
||||
$this->bodyValidator = $validator;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the attached option validator if one is attached.
|
||||
*/
|
||||
public function removeOptionValidator()
|
||||
{
|
||||
$this->optionValidator = array();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the attached body validator if one is attached.
|
||||
*/
|
||||
public function removeBodyValidator()
|
||||
{
|
||||
$this->bodyValidator = null;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a CodeDefinition with the current state of the builder.
|
||||
*
|
||||
* @return a new CodeDefinition instance
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
$definition = CodeDefinition::construct($this->tagName,
|
||||
$this->replacementText,
|
||||
$this->useOption,
|
||||
$this->parseContent,
|
||||
$this->nestLimit,
|
||||
$this->optionValidator,
|
||||
$this->bodyValidator);
|
||||
return $definition;
|
||||
}
|
||||
|
||||
}
|
19
app/jbbcode/codedefinitionset.class.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
namespace JBBCode;
|
||||
|
||||
defined('PROJECT_PATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* An interface for sets of code definitons.
|
||||
*
|
||||
* @author jbowens
|
||||
*/
|
||||
interface CodeDefinitionSet
|
||||
{
|
||||
|
||||
/**
|
||||
* Retrieves the CodeDefinitions within this set as an array.
|
||||
*/
|
||||
public function getCodeDefinitions();
|
||||
|
||||
}
|
70
app/jbbcode/defaultcodedefinitionset.class.php
Normal file
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
namespace JBBCode;
|
||||
|
||||
defined('PROJECT_PATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Provides a default set of common bbcode definitions.
|
||||
*
|
||||
* @author jbowens
|
||||
*/
|
||||
class DefaultCodeDefinitionSet implements CodeDefinitionSet
|
||||
{
|
||||
|
||||
/* The default code definitions in this set. */
|
||||
protected $definitions = array();
|
||||
|
||||
/**
|
||||
* Constructs the default code definitions.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
/* [b] bold tag */
|
||||
$builder = new CodeDefinitionBuilder('b', '<strong>{param}</strong>');
|
||||
array_push($this->definitions, $builder->build());
|
||||
|
||||
/* [i] italics tag */
|
||||
$builder = new CodeDefinitionBuilder('i', '<em>{param}</em>');
|
||||
array_push($this->definitions, $builder->build());
|
||||
|
||||
/* [u] underline tag */
|
||||
$builder = new CodeDefinitionBuilder('u', '<u>{param}</u>');
|
||||
array_push($this->definitions, $builder->build());
|
||||
|
||||
$urlValidator = new \JBBCode\validators\UrlValidator();
|
||||
|
||||
/* [url] link tag */
|
||||
$builder = new CodeDefinitionBuilder('url', '<a href="{param}">{param}</a>');
|
||||
$builder->setParseContent(false)->setBodyValidator($urlValidator);
|
||||
array_push($this->definitions, $builder->build());
|
||||
|
||||
/* [url=http://example.com] link tag */
|
||||
$builder = new CodeDefinitionBuilder('url', '<a href="{option}">{param}</a>');
|
||||
$builder->setUseOption(true)->setParseContent(true)->setOptionValidator($urlValidator);
|
||||
array_push($this->definitions, $builder->build());
|
||||
|
||||
/* [img] image tag */
|
||||
$builder = new CodeDefinitionBuilder('img', '<img src="{param}" />');
|
||||
$builder->setUseOption(false)->setParseContent(false)->setBodyValidator($urlValidator);
|
||||
array_push($this->definitions, $builder->build());
|
||||
|
||||
/* [img=alt text] image tag */
|
||||
$builder = new CodeDefinitionBuilder('img', '<img src="{param}" alt="{option}" />');
|
||||
$builder->setUseOption(true)->setParseContent(false)->setBodyValidator($urlValidator);
|
||||
array_push($this->definitions, $builder->build());
|
||||
|
||||
/* [color] color tag */
|
||||
$builder = new CodeDefinitionBuilder('color', '<span style="color: {option}">{param}</span>');
|
||||
$builder->setUseOption(true)->setOptionValidator(new \JBBCode\validators\CssColorValidator());
|
||||
array_push($this->definitions, $builder->build());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of the default code definitions.
|
||||
*/
|
||||
public function getCodeDefinitions()
|
||||
{
|
||||
return $this->definitions;
|
||||
}
|
||||
|
||||
}
|
66
app/jbbcode/documentelement.class.php
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
namespace JBBCode;
|
||||
|
||||
defined('PROJECT_PATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* A DocumentElement object represents the root of a document tree. All
|
||||
* documents represented by this document model should have one as its root.
|
||||
*
|
||||
* @author jbowens
|
||||
*/
|
||||
class DocumentElement extends ElementNode
|
||||
{
|
||||
/**
|
||||
* Constructs the document element node
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->setTagName("Document");
|
||||
$this->setNodeId(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see JBBCode.ElementNode::getAsBBCode()
|
||||
*
|
||||
* Returns the BBCode representation of this document
|
||||
*
|
||||
* @return this document's bbcode representation
|
||||
*/
|
||||
public function getAsBBCode()
|
||||
{
|
||||
$s = "";
|
||||
foreach($this->getChildren() as $child){
|
||||
$s .= $child->getAsBBCode();
|
||||
}
|
||||
|
||||
return $s;
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see JBBCode.ElementNode::getAsHTML()
|
||||
*
|
||||
* Documents don't add any html. They only exist as a container for their
|
||||
* children, so getAsHTML() simply iterates through the document's children,
|
||||
* returning their html.
|
||||
*
|
||||
* @return the HTML representation of this document
|
||||
*/
|
||||
public function getAsHTML()
|
||||
{
|
||||
$s = "";
|
||||
foreach($this->getChildren() as $child)
|
||||
$s .= $child->getAsHTML();
|
||||
|
||||
return $s;
|
||||
}
|
||||
|
||||
public function accept(NodeVisitor $visitor)
|
||||
{
|
||||
$visitor->visitDocumentElement($this);
|
||||
}
|
||||
|
||||
}
|
240
app/jbbcode/elementnode.class.php
Normal file
|
@ -0,0 +1,240 @@
|
|||
<?php
|
||||
namespace JBBCode;
|
||||
|
||||
defined('PROJECT_PATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* An element within the tree. Consists of a tag name which defines the type of the
|
||||
* element and any number of Node children. It also contains a CodeDefinition matching
|
||||
* the tag name of the element.
|
||||
*
|
||||
* @author jbowens
|
||||
*/
|
||||
class ElementNode extends Node
|
||||
{
|
||||
/* The tagname of this element, for i.e. "b" in [b]bold[/b] */
|
||||
protected $tagName;
|
||||
|
||||
/* The attribute, if any, of this element node */
|
||||
protected $attribute;
|
||||
|
||||
/* The child nodes contained within this element */
|
||||
protected $children;
|
||||
|
||||
/* The code definition that defines this element's behavior */
|
||||
protected $codeDefinition;
|
||||
|
||||
/* How deeply this node is nested */
|
||||
protected $nestDepth;
|
||||
|
||||
/**
|
||||
* Constructs the element node
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->children = array();
|
||||
$this->nestDepth = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts the given NodeVisitor. This is part of an implementation
|
||||
* of the Visitor pattern.
|
||||
*
|
||||
* @param $nodeVisitor the visitor attempting to visit this node
|
||||
*/
|
||||
public function accept(NodeVisitor $nodeVisitor)
|
||||
{
|
||||
$nodeVisitor->visitElementNode($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the CodeDefinition that defines this element.
|
||||
*
|
||||
* @return this element's code definition
|
||||
*/
|
||||
public function getCodeDefinition()
|
||||
{
|
||||
return $this->codeDefinition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the CodeDefinition that defines this element.
|
||||
*
|
||||
* @param codeDef the code definition that defines this element node
|
||||
*/
|
||||
public function setCodeDefinition(CodeDefinition $codeDef)
|
||||
{
|
||||
$this->codeDefinition = $codeDef;
|
||||
$this->setTagName($codeDef->getTagName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tag name of this element.
|
||||
*
|
||||
* @return the element's tag name
|
||||
*/
|
||||
public function getTagName()
|
||||
{
|
||||
return $this->tagName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the attribute (used as the option in bbcode definitions) of this element.
|
||||
*
|
||||
* @return the attribute of this element
|
||||
*/
|
||||
public function getAttribute()
|
||||
{
|
||||
return $this->attribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the children of this element.
|
||||
*
|
||||
* @return an array of this node's child nodes
|
||||
*/
|
||||
public function getChildren()
|
||||
{
|
||||
return $this->children;
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see JBBCode.Node::getAsText()
|
||||
*
|
||||
* Returns the element as text (not including any bbcode markup)
|
||||
*
|
||||
* @return the plain text representation of this node
|
||||
*/
|
||||
public function getAsText()
|
||||
{
|
||||
if ($this->codeDefinition) {
|
||||
return $this->codeDefinition->asText($this);
|
||||
} else {
|
||||
$s = "";
|
||||
foreach ($this->getChildren() as $child)
|
||||
$s .= $child->getAsText();
|
||||
return $s;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see JBBCode.Node::getAsBBCode()
|
||||
*
|
||||
* Returns the element as bbcode (with all unclosed tags closed)
|
||||
*
|
||||
* @return the bbcode representation of this element
|
||||
*/
|
||||
public function getAsBBCode()
|
||||
{
|
||||
$str = "[".$this->tagName;
|
||||
if (!empty($this->attribute)) {
|
||||
|
||||
foreach($this->attribute as $key => $value){
|
||||
if($key == $this->tagName){
|
||||
$str .= "=".$value;
|
||||
}
|
||||
else{
|
||||
$str .= " ".$key."=" . $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
$str .= "]";
|
||||
foreach ($this->getChildren() as $child) {
|
||||
$str .= $child->getAsBBCode();
|
||||
}
|
||||
$str .= "[/".$this->tagName."]";
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see JBBCode.Node::getAsHTML()
|
||||
*
|
||||
* Returns the element as html with all replacements made
|
||||
*
|
||||
* @return the html representation of this node
|
||||
*/
|
||||
public function getAsHTML()
|
||||
{
|
||||
if($this->codeDefinition) {
|
||||
return $this->codeDefinition->asHtml($this);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a child to this node's content. A child may be a TextNode, or
|
||||
* another ElementNode... or anything else that may extend the
|
||||
* abstract Node class.
|
||||
*
|
||||
* @param child the node to add as a child
|
||||
*/
|
||||
public function addChild(Node $child)
|
||||
{
|
||||
array_push($this->children, $child);
|
||||
$child->setParent($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a child from this node's contnet.
|
||||
*
|
||||
* @param child the child node to remove
|
||||
*/
|
||||
public function removeChild(Node $child)
|
||||
{
|
||||
foreach ($this->children as $key => $value) {
|
||||
if ($value == $child)
|
||||
unset($this->children[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the tag name of this element node.
|
||||
*
|
||||
* @param tagName the element's new tag name
|
||||
*/
|
||||
public function setTagName($tagName)
|
||||
{
|
||||
$this->tagName = $tagName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the attribute (option) of this element node.
|
||||
*
|
||||
* @param attribute the attribute of this element node
|
||||
*/
|
||||
public function setAttribute($attribute)
|
||||
{
|
||||
$this->attribute = $attribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Traverses the parse tree upwards, going from parent to parent, until it finds a
|
||||
* parent who has the given tag name. Returns the parent with the matching tag name
|
||||
* if it exists, otherwise returns null.
|
||||
*
|
||||
* @param str the tag name to search for
|
||||
*
|
||||
* @return the closest parent with the given tag name
|
||||
*/
|
||||
public function closestParentOfType($str)
|
||||
{
|
||||
$str = strtolower($str);
|
||||
$currentEl = $this;
|
||||
|
||||
while (strtolower($currentEl->getTagName()) != $str && $currentEl->hasParent()) {
|
||||
$currentEl = $currentEl->getParent();
|
||||
}
|
||||
|
||||
if (strtolower($currentEl->getTagName()) != $str) {
|
||||
return null;
|
||||
} else {
|
||||
return $currentEl;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
21
app/jbbcode/inputvalidator.class.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
namespace JBBCode;
|
||||
|
||||
defined('PROJECT_PATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Defines an interface for validation filters for bbcode options and
|
||||
* parameters.
|
||||
*
|
||||
* @author jbowens
|
||||
* @since May 2013
|
||||
*/
|
||||
interface InputValidator
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns true iff the given input is valid, false otherwise.
|
||||
*/
|
||||
public function validate($input);
|
||||
|
||||
}
|
110
app/jbbcode/node.class.php
Normal file
|
@ -0,0 +1,110 @@
|
|||
<?php
|
||||
namespace JBBCode;
|
||||
|
||||
defined('PROJECT_PATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* A node within the document tree.
|
||||
*
|
||||
* Known subclasses: TextNode, ElementNode
|
||||
*
|
||||
* @author jbowens
|
||||
*/
|
||||
abstract class Node
|
||||
{
|
||||
/* Pointer to the parent node of this node */
|
||||
protected $parent;
|
||||
|
||||
/* The node id of this node */
|
||||
protected $nodeid;
|
||||
|
||||
/**
|
||||
* Returns the node id of this node. (Not really ever used. Dependent upon the parse tree the node exists within.)
|
||||
*
|
||||
* @return this node's id
|
||||
*/
|
||||
public function getNodeId()
|
||||
{
|
||||
return $this->nodeid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this node's immediate parent.
|
||||
*
|
||||
* @return the node's parent
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
return $this->parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if this node has a parent.
|
||||
*
|
||||
* @return true if this node has a parent, false otherwise
|
||||
*/
|
||||
public function hasParent()
|
||||
{
|
||||
return $this->parent != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this is a text node. Returns false otherwise.
|
||||
* (Overridden by TextNode to return true)
|
||||
*
|
||||
* @return true if this node is a text node
|
||||
*/
|
||||
public function isTextNode()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a NodeVisitor
|
||||
*
|
||||
* @param nodeVisitor the NodeVisitor traversing the graph
|
||||
*/
|
||||
abstract public function accept(NodeVisitor $nodeVisitor);
|
||||
|
||||
/**
|
||||
* Returns this node as text (without any bbcode markup)
|
||||
*
|
||||
* @return the plain text representation of this node
|
||||
*/
|
||||
abstract public function getAsText();
|
||||
|
||||
/**
|
||||
* Returns this node as bbcode
|
||||
*
|
||||
* @return the bbcode representation of this node
|
||||
*/
|
||||
abstract public function getAsBBCode();
|
||||
|
||||
/**
|
||||
* Returns this node as HTML
|
||||
*
|
||||
* @return the html representation of this node
|
||||
*/
|
||||
abstract public function getAsHTML();
|
||||
|
||||
/**
|
||||
* Sets this node's parent to be the given node.
|
||||
*
|
||||
* @param parent the node to set as this node's parent
|
||||
*/
|
||||
public function setParent(Node $parent)
|
||||
{
|
||||
$this->parent = $parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this node's nodeid
|
||||
*
|
||||
* @param nodeid this node's node id
|
||||
*/
|
||||
public function setNodeId($nodeid)
|
||||
{
|
||||
$this->nodeid = $nodeid;
|
||||
}
|
||||
|
||||
}
|
21
app/jbbcode/nodevisitor.class.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
namespace JBBCode;
|
||||
|
||||
defined('PROJECT_PATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Defines an interface for a visitor to traverse the node graph.
|
||||
*
|
||||
* @author jbowens
|
||||
* @since January 2013
|
||||
*/
|
||||
interface NodeVisitor
|
||||
{
|
||||
|
||||
public function visitDocumentElement(DocumentElement $documentElement);
|
||||
|
||||
public function visitTextNode(TextNode $textNode);
|
||||
|
||||
public function visitElementNode(ElementNode $elementNode);
|
||||
|
||||
}
|
648
app/jbbcode/parser.class.php
Normal file
|
@ -0,0 +1,648 @@
|
|||
<?php
|
||||
namespace JBBCode;
|
||||
|
||||
defined('PROJECT_PATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* BBCodeParser is the main parser class that constructs and stores the parse tree. Through this class
|
||||
* new bbcode definitions can be added, and documents may be parsed and converted to html/bbcode/plaintext, etc.
|
||||
*
|
||||
* @author jbowens
|
||||
*/
|
||||
class Parser
|
||||
{
|
||||
|
||||
const OPTION_STATE_DEFAULT = 0;
|
||||
const OPTION_STATE_TAGNAME = 1;
|
||||
const OPTION_STATE_KEY = 2;
|
||||
const OPTION_STATE_VALUE = 3;
|
||||
const OPTION_STATE_QUOTED_VALUE = 4;
|
||||
const OPTION_STATE_JAVASCRIPT = 5;
|
||||
|
||||
/* The root element of the parse tree */
|
||||
protected $treeRoot;
|
||||
|
||||
/* The list of bbcodes to be used by the parser. */
|
||||
protected $bbcodes;
|
||||
|
||||
/* The next node id to use. This is used while parsing. */
|
||||
protected $nextNodeid;
|
||||
|
||||
/**
|
||||
* Constructs an instance of the BBCode parser
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->reset();
|
||||
$this->bbcodes = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a simple (text-replacement only) bbcode definition
|
||||
*
|
||||
* @param string $tagName the tag name of the code (for example the b in [b])
|
||||
* @param string $replace the html to use, with {param} and optionally {option} for replacements
|
||||
* @param boolean $useOption whether or not this bbcode uses the secondary {option} replacement
|
||||
* @param boolean $parseContent whether or not to parse the content within these elements
|
||||
* @param integer $nestLimit an optional limit of the number of elements of this kind that can be nested within
|
||||
* each other before the parser stops parsing them.
|
||||
* @param InputValidator $optionValidator the validator to run {option} through
|
||||
* @param BodyValidator $bodyValidator the validator to run {param} through (only used if $parseContent == false)
|
||||
*
|
||||
* @return Parser
|
||||
*/
|
||||
public function addBBCode($tagName, $replace, $useOption = false, $parseContent = true, $nestLimit = -1,
|
||||
InputValidator $optionValidator = null, InputValidator $bodyValidator = null)
|
||||
{
|
||||
$builder = new CodeDefinitionBuilder($tagName, $replace);
|
||||
|
||||
$builder->setUseOption($useOption);
|
||||
$builder->setParseContent($parseContent);
|
||||
$builder->setNestLimit($nestLimit);
|
||||
|
||||
if ($optionValidator) {
|
||||
$builder->setOptionValidator($optionValidator);
|
||||
}
|
||||
|
||||
if ($bodyValidator) {
|
||||
$builder->setBodyValidator($bodyValidator);
|
||||
}
|
||||
|
||||
$this->addCodeDefinition($builder->build());
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a complex bbcode definition. You may subclass the CodeDefinition class, instantiate a definition of your new
|
||||
* class and add it to the parser through this method.
|
||||
*
|
||||
* @param CodeDefinition $definition the bbcode definition to add
|
||||
*
|
||||
* @return Parser
|
||||
*/
|
||||
public function addCodeDefinition(CodeDefinition $definition)
|
||||
{
|
||||
array_push($this->bbcodes, $definition);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a set of CodeDefinitions.
|
||||
*
|
||||
* @param CodeDefinitionSet $set the set of definitions to add
|
||||
*
|
||||
* @return Parser
|
||||
*/
|
||||
public function addCodeDefinitionSet(CodeDefinitionSet $set) {
|
||||
foreach ($set->getCodeDefinitions() as $def) {
|
||||
$this->addCodeDefinition($def);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entire parse tree as text. Only {param} content is returned. BBCode markup will be ignored.
|
||||
*
|
||||
* @return string a text representation of the parse tree
|
||||
*/
|
||||
public function getAsText()
|
||||
{
|
||||
return $this->treeRoot->getAsText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entire parse tree as bbcode. This will be identical to the inputted string, except unclosed tags
|
||||
* will be closed.
|
||||
*
|
||||
* @return string a bbcode representation of the parse tree
|
||||
*/
|
||||
public function getAsBBCode()
|
||||
{
|
||||
return $this->treeRoot->getAsBBCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entire parse tree as HTML. All BBCode replacements will be made. This is generally the method
|
||||
* you will want to use to retrieve the parsed bbcode.
|
||||
*
|
||||
* @return string a parsed html string
|
||||
*/
|
||||
public function getAsHTML()
|
||||
{
|
||||
return $this->treeRoot->getAsHTML();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts the given NodeVisitor at the root.
|
||||
*
|
||||
* @param NodeVisitor a NodeVisitor
|
||||
*
|
||||
* @return Parser
|
||||
*/
|
||||
public function accept(NodeVisitor $nodeVisitor)
|
||||
{
|
||||
$this->treeRoot->accept($nodeVisitor);
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Constructs the parse tree from a string of bbcode markup.
|
||||
*
|
||||
* @param string $str the bbcode markup to parse
|
||||
*
|
||||
* @return Parser
|
||||
*/
|
||||
public function parse($str)
|
||||
{
|
||||
/* Set the tree root back to a fresh DocumentElement. */
|
||||
$this->reset();
|
||||
|
||||
$parent = $this->treeRoot;
|
||||
$tokenizer = new Tokenizer($str);
|
||||
|
||||
while ($tokenizer->hasNext()) {
|
||||
$parent = $this->parseStartState($parent, $tokenizer);
|
||||
if ($parent->getCodeDefinition() && false ===
|
||||
$parent->getCodeDefinition()->parseContent()) {
|
||||
/* We're inside an element that does not allow its contents to be parseable. */
|
||||
$this->parseAsTextUntilClose($parent, $tokenizer);
|
||||
$parent = $parent->getParent();
|
||||
}
|
||||
}
|
||||
|
||||
/* We parsed ignoring nest limits. Do an O(n) traversal to remove any elements that
|
||||
* are nested beyond their CodeDefinition's nest limit. */
|
||||
$this->removeOverNestedElements();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes any elements that are nested beyond their nest limit from the parse tree. This
|
||||
* method is now deprecated. In a future release its access privileges will be made
|
||||
* protected.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public function removeOverNestedElements()
|
||||
{
|
||||
$nestLimitVisitor = new \JBBCode\visitors\NestLimitVisitor();
|
||||
$this->accept($nestLimitVisitor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the old parse tree if one exists.
|
||||
*/
|
||||
protected function reset()
|
||||
{
|
||||
// remove any old tree information
|
||||
$this->treeRoot = new DocumentElement();
|
||||
/* The document element is created with nodeid 0. */
|
||||
$this->nextNodeid = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a bbcode exists based on its tag name and whether or not it uses an option
|
||||
*
|
||||
* @param string $tagName the bbcode tag name to check
|
||||
* @param boolean $usesOption whether or not the bbcode accepts an option
|
||||
*
|
||||
* @return bool true if the code exists, false otherwise
|
||||
*/
|
||||
public function codeExists($tagName, $usesOption = false)
|
||||
{
|
||||
foreach ($this->bbcodes as $code) {
|
||||
if (strtolower($tagName) == $code->getTagName() && $usesOption == $code->usesOption()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the CodeDefinition of a bbcode with the matching tag name and usesOption parameter
|
||||
*
|
||||
* @param string $tagName the tag name of the bbcode being searched for
|
||||
* @param boolean $usesOption whether or not the bbcode accepts an option
|
||||
*
|
||||
* @return CodeDefinition if the bbcode exists, null otherwise
|
||||
*/
|
||||
public function getCode($tagName, $usesOption = false)
|
||||
{
|
||||
foreach ($this->bbcodes as $code) {
|
||||
if (strtolower($tagName) == $code->getTagName() && $code->usesOption() == $usesOption) {
|
||||
return $code;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a set of default, standard bbcode definitions commonly used across the web.
|
||||
*
|
||||
* This method is now deprecated. Please use DefaultCodeDefinitionSet and
|
||||
* addCodeDefinitionSet() instead.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public function loadDefaultCodes()
|
||||
{
|
||||
$defaultSet = new DefaultCodeDefinitionSet();
|
||||
$this->addCodeDefinitionSet($defaultSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new text node with the given parent and text string.
|
||||
*
|
||||
* @param $parent the parent of the text node
|
||||
* @param $string the text of the text node
|
||||
*
|
||||
* @return TextNode the newly created TextNode
|
||||
*/
|
||||
protected function createTextNode(ElementNode $parent, $string)
|
||||
{
|
||||
if (count($parent->getChildren())) {
|
||||
$children = $parent->getChildren();
|
||||
$lastElement = end($children);
|
||||
reset($children);
|
||||
|
||||
if ($lastElement->isTextNode()) {
|
||||
$lastElement->setValue($lastElement->getValue() . $string);
|
||||
return $lastElement;
|
||||
}
|
||||
}
|
||||
|
||||
$textNode = new TextNode($string);
|
||||
$textNode->setNodeId(++$this->nextNodeid);
|
||||
$parent->addChild($textNode);
|
||||
return $textNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* jBBCode parsing logic is loosely modelled after a FSM. While not every function maps
|
||||
* to a unique DFSM state, each function handles the logic of one or more FSM states.
|
||||
* This function handles the beginning parse state when we're not currently in a tag
|
||||
* name.
|
||||
*
|
||||
* @param ElementNode $parent the current parent node we're under
|
||||
* @param Tokenizer $tokenizer the tokenizer we're using
|
||||
*
|
||||
* @return ElementNode the new parent we should use for the next iteration.
|
||||
*/
|
||||
protected function parseStartState(ElementNode $parent, Tokenizer $tokenizer)
|
||||
{
|
||||
$next = $tokenizer->next();
|
||||
|
||||
if ('[' == $next) {
|
||||
return $this->parseTagOpen($parent, $tokenizer);
|
||||
}
|
||||
else {
|
||||
$this->createTextNode($parent, $next);
|
||||
/* Drop back into the main parse loop which will call this
|
||||
* same method again. */
|
||||
return $parent;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function handles parsing the beginnings of an open tag. When we see a [
|
||||
* at an appropriate time, this function is entered.
|
||||
*
|
||||
* @param ElementNode $parent the current parent node
|
||||
* @param Tokenizer $tokenizer the tokenizer we're using
|
||||
*
|
||||
* @return ElementNode the new parent node
|
||||
*/
|
||||
protected function parseTagOpen(ElementNode $parent, Tokenizer $tokenizer)
|
||||
{
|
||||
|
||||
if (!$tokenizer->hasNext()) {
|
||||
/* The [ that sent us to this state was just a trailing [, not the
|
||||
* opening for a new tag. Treat it as such. */
|
||||
$this->createTextNode($parent, '[');
|
||||
return $parent;
|
||||
}
|
||||
|
||||
$next = $tokenizer->next();
|
||||
|
||||
/* This while loop could be replaced by a recursive call to this same method,
|
||||
* which would likely be a lot clearer but I decided to use a while loop to
|
||||
* prevent stack overflow with a string like [[[[[[[[[...[[[.
|
||||
*/
|
||||
while ('[' == $next) {
|
||||
/* The previous [ was just a random bracket that should be treated as text.
|
||||
* Continue until we get a non open bracket. */
|
||||
$this->createTextNode($parent, '[');
|
||||
if (!$tokenizer->hasNext()) {
|
||||
$this->createTextNode($parent, '[');
|
||||
return $parent;
|
||||
}
|
||||
$next = $tokenizer->next();
|
||||
}
|
||||
|
||||
if (!$tokenizer->hasNext()) {
|
||||
$this->createTextNode($parent, '['.$next);
|
||||
return $parent;
|
||||
}
|
||||
|
||||
$after_next = $tokenizer->next();
|
||||
$tokenizer->stepBack();
|
||||
|
||||
if ($after_next != ']')
|
||||
{
|
||||
$this->createTextNode($parent, '['.$next);
|
||||
return $parent;
|
||||
}
|
||||
|
||||
/* At this point $next is either ']' or plain text. */
|
||||
if (']' == $next) {
|
||||
$this->createTextNode($parent, '[');
|
||||
$this->createTextNode($parent, ']');
|
||||
return $parent;
|
||||
} else {
|
||||
/* $next is plain text... likely a tag name. */
|
||||
return $this->parseTag($parent, $tokenizer, $next);
|
||||
}
|
||||
}
|
||||
|
||||
protected function parseOptions($tagContent)
|
||||
{
|
||||
$buffer = "";
|
||||
$tagName = "";
|
||||
$state = static::OPTION_STATE_TAGNAME;
|
||||
$keys = array();
|
||||
$values = array();
|
||||
$options = array();
|
||||
|
||||
$len = strlen($tagContent);
|
||||
$done = false;
|
||||
$idx = 0;
|
||||
|
||||
try{
|
||||
while(!$done){
|
||||
$char = $idx < $len ? $tagContent[$idx]:null;
|
||||
switch($state){
|
||||
case static::OPTION_STATE_TAGNAME:
|
||||
switch($char){
|
||||
case '=':
|
||||
$state = static::OPTION_STATE_VALUE;
|
||||
$tagName = $buffer;
|
||||
$keys[] = $tagName;
|
||||
$buffer = "";
|
||||
break;
|
||||
case ' ':
|
||||
$state = static::OPTION_STATE_DEFAULT;
|
||||
$tagName = $buffer;
|
||||
$buffer = '';
|
||||
$keys[] = $tagName;
|
||||
break;
|
||||
|
||||
case null:
|
||||
$tagName = $buffer;
|
||||
$buffer = '';
|
||||
$keys[] = $tagName;
|
||||
break;
|
||||
default:
|
||||
$buffer .= $char;
|
||||
}
|
||||
break;
|
||||
|
||||
case static::OPTION_STATE_DEFAULT:
|
||||
switch($char){
|
||||
case ' ':
|
||||
// do nothing
|
||||
default:
|
||||
$state = static::OPTION_STATE_KEY;
|
||||
$buffer .= $char;
|
||||
}
|
||||
break;
|
||||
|
||||
case static::OPTION_STATE_VALUE:
|
||||
switch($char){
|
||||
case '"':
|
||||
$state = static::OPTION_STATE_QUOTED_VALUE;
|
||||
break;
|
||||
case null: // intentional fall-through
|
||||
case ' ': // key=value<space> delimits to next key
|
||||
$values[] = $buffer;
|
||||
$buffer = "";
|
||||
$state = static::OPTION_STATE_KEY;
|
||||
break;
|
||||
case ":":
|
||||
if($buffer=="javascript"){
|
||||
$state = static::OPTION_STATE_JAVASCRIPT;
|
||||
}
|
||||
$buffer .= $char;
|
||||
break;
|
||||
default:
|
||||
$buffer .= $char;
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case static::OPTION_STATE_JAVASCRIPT:
|
||||
switch($char){
|
||||
case ";":
|
||||
$buffer .= $char;
|
||||
$values[] = $buffer;
|
||||
$buffer = "";
|
||||
$state = static::OPTION_STATE_KEY;
|
||||
|
||||
break;
|
||||
default:
|
||||
$buffer .= $char;
|
||||
}
|
||||
break;
|
||||
|
||||
case static::OPTION_STATE_KEY:
|
||||
switch($char){
|
||||
case '=':
|
||||
$state = static::OPTION_STATE_VALUE;
|
||||
$keys[] = $buffer;
|
||||
$buffer = '';
|
||||
break;
|
||||
case ' ': // ignore <space>key=value
|
||||
break;
|
||||
default:
|
||||
$buffer .= $char;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case static::OPTION_STATE_QUOTED_VALUE:
|
||||
switch($char){
|
||||
case null:
|
||||
case '"':
|
||||
$state = static::OPTION_STATE_KEY;
|
||||
$values[] = $buffer;
|
||||
$buffer = '';
|
||||
|
||||
// peek ahead. If the next character is not a space or a closing brace, we have a bad tag and need to abort
|
||||
if(isset($tagContent[$idx+1]) && $tagContent[$idx+1]!=" " && $tagContent[$idx+1]!="]" ){
|
||||
throw new ParserException("Badly formed attribute: $tagContent");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$buffer .= $char;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if(!empty($char)){
|
||||
$state = static::OPTION_STATE_KEY;
|
||||
}
|
||||
|
||||
}
|
||||
if($idx >= $len){
|
||||
$done = true;
|
||||
}
|
||||
$idx++;
|
||||
}
|
||||
|
||||
if(count($keys) && count($values)){
|
||||
if(count($keys)==(count($values)+1)){
|
||||
array_unshift($values, "");
|
||||
}
|
||||
|
||||
$options = array_combine($keys, $values);
|
||||
}
|
||||
}
|
||||
catch(ParserException $e){
|
||||
// if we're in this state, then something evidently went wrong. We'll consider everything that came after the tagname to be the attribute for that keyname
|
||||
$options[$tagName]= substr($tagContent, strpos($tagContent, "=")+1);
|
||||
}
|
||||
return array($tagName, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the next step in parsing a tag. It's possible for it to still be invalid at this
|
||||
* point but many of the basic invalid tag name conditions have already been handled.
|
||||
*
|
||||
* @param ElementNode $parent the current parent element
|
||||
* @param Tokenizer $tokenizer the tokenizer we're using
|
||||
* @param string $tagContent the text between the [ and the ], assuming there is actually a ]
|
||||
*
|
||||
* @return ElementNode the new parent element
|
||||
*/
|
||||
protected function parseTag(ElementNode $parent, Tokenizer $tokenizer, $tagContent)
|
||||
{
|
||||
|
||||
$next;
|
||||
if (!$tokenizer->hasNext() || ($next = $tokenizer->next()) != ']') {
|
||||
/* This is a malformed tag. Both the previous [ and the tagContent
|
||||
* is really just plain text. */
|
||||
$this->createTextNode($parent, '[');
|
||||
$this->createTextNode($parent, $tagContent);
|
||||
return $parent;
|
||||
}
|
||||
|
||||
/* This is a well-formed tag consisting of [something] or [/something], but
|
||||
* we still need to ensure that 'something' is a valid tag name. Additionally,
|
||||
* if it's a closing tag, we need to ensure that there was a previous matching
|
||||
* opening tag.
|
||||
*/
|
||||
/* There could be attributes. */
|
||||
list($tmpTagName, $options) = $this->parseOptions($tagContent);
|
||||
|
||||
// $tagPieces = explode('=', $tagContent);
|
||||
// $tmpTagName = $tagPieces[0];
|
||||
|
||||
$actualTagName;
|
||||
if ('' != $tmpTagName && '/' == $tmpTagName[0]) {
|
||||
/* This is a closing tag name. */
|
||||
$actualTagName = substr($tmpTagName, 1);
|
||||
} else {
|
||||
$actualTagName = $tmpTagName;
|
||||
}
|
||||
|
||||
if ('' != $tmpTagName && '/' == $tmpTagName[0]) {
|
||||
/* This is attempting to close an open tag. We must verify that there exists an
|
||||
* open tag of the same type and that there is no option (options on closing
|
||||
* tags don't make any sense). */
|
||||
$elToClose = $parent->closestParentOfType($actualTagName);
|
||||
if (null == $elToClose || count($options) > 1) {
|
||||
/* Closing an unopened tag or has an option. Treat everything as plain text. */
|
||||
$this->createTextNode($parent, '[');
|
||||
$this->createTextNode($parent, $tagContent);
|
||||
$this->createTextNode($parent, ']');
|
||||
return $parent;
|
||||
} else {
|
||||
/* We're closing $elToClose. In order to do that, we just need to return
|
||||
* $elToClose's parent, since that will change our effective parent to be
|
||||
* elToClose's parent. */
|
||||
return $elToClose->getParent();
|
||||
}
|
||||
}
|
||||
|
||||
/* Verify that this is a known bbcode tag name. */
|
||||
if ('' == $actualTagName || !$this->codeExists($actualTagName, !empty($options))) {
|
||||
/* This is an invalid tag name! Treat everything we've seen as plain text. */
|
||||
$this->createTextNode($parent, '[');
|
||||
$this->createTextNode($parent, $tagContent);
|
||||
$this->createTextNode($parent, ']');
|
||||
return $parent;
|
||||
}
|
||||
|
||||
/* If we're here, this is a valid opening tag. Let's make a new node for it. */
|
||||
$el = new ElementNode();
|
||||
$el->setNodeId(++$this->nextNodeid);
|
||||
$code = $this->getCode($actualTagName, !empty($options));
|
||||
$el->setCodeDefinition($code);
|
||||
if (!empty($options)) {
|
||||
/* We have an attribute we should save. */
|
||||
$el->setAttribute($options);
|
||||
}
|
||||
$parent->addChild($el);
|
||||
return $el;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles parsing elements whose CodeDefinitions disable parsing of element
|
||||
* contents. This function uses a rolling window of 3 tokens until it finds the
|
||||
* appropriate closing tag or reaches the end of the token stream.
|
||||
*
|
||||
* @param ElementNode $parent the current parent element
|
||||
* @param Tokenizer $tokenizer the tokenizer we're using
|
||||
*
|
||||
* @return ElementNode the new parent element
|
||||
*/
|
||||
protected function parseAsTextUntilClose(ElementNode $parent, Tokenizer $tokenizer)
|
||||
{
|
||||
/* $parent's code definition doesn't allow its contents to be parsed. Here we use
|
||||
* a sliding window of three tokens until we find [ /tagname ], signifying the
|
||||
* end of the parent. */
|
||||
if (!$tokenizer->hasNext()) {
|
||||
return $parent;
|
||||
}
|
||||
$prevPrev = $tokenizer->next();
|
||||
if (!$tokenizer->hasNext()) {
|
||||
$this->createTextNode($parent, $prevPrev);
|
||||
return $parent;
|
||||
}
|
||||
$prev = $tokenizer->next();
|
||||
if (!$tokenizer->hasNext()) {
|
||||
$this->createTextNode($parent, $prevPrev);
|
||||
$this->createTextNode($parent, $prev);
|
||||
return $parent;
|
||||
}
|
||||
$curr = $tokenizer->next();
|
||||
while ('[' != $prevPrev || '/'.$parent->getTagName() != strtolower($prev) ||
|
||||
']' != $curr) {
|
||||
$this->createTextNode($parent, $prevPrev);
|
||||
$prevPrev = $prev;
|
||||
$prev = $curr;
|
||||
if (!$tokenizer->hasNext()) {
|
||||
$this->createTextNode($parent, $prevPrev);
|
||||
$this->createTextNode($parent, $prev);
|
||||
return $parent;
|
||||
}
|
||||
$curr = $tokenizer->next();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
9
app/jbbcode/parserexception.class.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
namespace JBBCode;
|
||||
|
||||
defined('PROJECT_PATH') OR exit('No direct script access allowed');
|
||||
|
||||
use Exception;
|
||||
|
||||
class ParserException extends Exception{
|
||||
}
|
101
app/jbbcode/textnode.class.php
Normal file
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
namespace JBBCode;
|
||||
|
||||
defined('PROJECT_PATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Represents a piece of text data. TextNodes never have children.
|
||||
*
|
||||
* @author jbowens
|
||||
*/
|
||||
class TextNode extends Node
|
||||
{
|
||||
/* The value of this text node */
|
||||
protected $value;
|
||||
|
||||
/**
|
||||
* Constructs a text node from its text string
|
||||
*
|
||||
* @param string $val
|
||||
*/
|
||||
public function __construct($val)
|
||||
{
|
||||
$this->value = $val;
|
||||
}
|
||||
|
||||
public function accept(NodeVisitor $visitor)
|
||||
{
|
||||
$visitor->visitTextNode($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see JBBCode.Node::isTextNode()
|
||||
*
|
||||
* returns true
|
||||
*/
|
||||
public function isTextNode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the text string value of this text node.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see JBBCode.Node::getAsText()
|
||||
*
|
||||
* Returns the text representation of this node.
|
||||
*
|
||||
* @return this node represented as text
|
||||
*/
|
||||
public function getAsText()
|
||||
{
|
||||
return $this->getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see JBBCode.Node::getAsBBCode()
|
||||
*
|
||||
* Returns the bbcode representation of this node. (Just its value)
|
||||
*
|
||||
* @return this node represented as bbcode
|
||||
*/
|
||||
public function getAsBBCode()
|
||||
{
|
||||
return $this->getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see JBBCode.Node::getAsHTML()
|
||||
*
|
||||
* Returns the html representation of this node. (Just its value)
|
||||
*
|
||||
* @return this node represented as HTML
|
||||
*/
|
||||
public function getAsHTML()
|
||||
{
|
||||
return $this->getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits the text value contained within this text node.
|
||||
*
|
||||
* @param newValue the new text value of the text node
|
||||
*/
|
||||
public function setValue($newValue)
|
||||
{
|
||||
$this->value = $newValue;
|
||||
}
|
||||
|
||||
}
|
106
app/jbbcode/tokenizer.class.php
Normal file
|
@ -0,0 +1,106 @@
|
|||
<?php
|
||||
namespace JBBCode;
|
||||
|
||||
defined('PROJECT_PATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* This Tokenizer is used while constructing the parse tree. The tokenizer
|
||||
* handles splitting the input into brackets and miscellaneous text. The
|
||||
* parser is then built as a FSM ontop of these possible inputs.
|
||||
*
|
||||
* @author jbowens
|
||||
*/
|
||||
class Tokenizer
|
||||
{
|
||||
|
||||
protected $tokens = array();
|
||||
protected $i = -1;
|
||||
|
||||
/**
|
||||
* Constructs a tokenizer from the given string. The string will be tokenized
|
||||
* upon construction.
|
||||
*
|
||||
* @param $str the string to tokenize
|
||||
*/
|
||||
public function __construct($str)
|
||||
{
|
||||
$strStart = 0;
|
||||
for ($index = 0; $index < strlen($str); ++$index) {
|
||||
if (']' == $str[$index] || '[' == $str[$index]) {
|
||||
/* Are there characters in the buffer from a previous string? */
|
||||
if ($strStart < $index) {
|
||||
array_push($this->tokens, substr($str, $strStart, $index - $strStart));
|
||||
$strStart = $index;
|
||||
}
|
||||
|
||||
/* Add the [ or ] to the tokens array. */
|
||||
array_push($this->tokens, $str[$index]);
|
||||
$strStart = $index+1;
|
||||
}
|
||||
}
|
||||
|
||||
if ($strStart < strlen($str)) {
|
||||
/* There are still characters in the buffer. Add them to the tokens. */
|
||||
array_push($this->tokens, substr($str, $strStart, strlen($str) - $strStart));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if there is another token in the token stream.
|
||||
*/
|
||||
public function hasNext()
|
||||
{
|
||||
return count($this->tokens) > 1 + $this->i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Advances the token stream to the next token and returns the new token.
|
||||
*/
|
||||
public function next()
|
||||
{
|
||||
if (!$this->hasNext()) {
|
||||
return null;
|
||||
} else {
|
||||
return $this->tokens[++$this->i];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the current token.
|
||||
*/
|
||||
public function current()
|
||||
{
|
||||
if ($this->i < 0) {
|
||||
return null;
|
||||
} else {
|
||||
return $this->tokens[$this->i];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the token stream back a token.
|
||||
*/
|
||||
public function stepBack()
|
||||
{
|
||||
if ($this->i > -1) {
|
||||
$this->i--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Restarts the tokenizer, returning to the beginning of the token stream.
|
||||
*/
|
||||
public function restart()
|
||||
{
|
||||
$this->i = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* toString method that returns the entire string from the current index on.
|
||||
*/
|
||||
public function toString()
|
||||
{
|
||||
return implode('', array_slice($this->tokens, $this->i + 1));
|
||||
}
|
||||
|
||||
}
|
29
app/jbbcode/validators/csscolorvalidator.class.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
namespace JBBCode\validators;
|
||||
|
||||
defined('PROJECT_PATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* An InputValidator for CSS color values. This is a very rudimentary
|
||||
* validator. It will allow a lot of color values that are invalid. However,
|
||||
* it shouldn't allow any invalid color values that are also a security
|
||||
* concern.
|
||||
*
|
||||
* @author jbowens
|
||||
* @since May 2013
|
||||
*/
|
||||
class CssColorValidator implements \JBBCode\InputValidator
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns true if $input uses only valid CSS color value
|
||||
* characters.
|
||||
*
|
||||
* @param $input the string to validate
|
||||
*/
|
||||
public function validate($input)
|
||||
{
|
||||
return (bool) preg_match('/^[A-z0-9\-#., ()%]+$/', $input);
|
||||
}
|
||||
|
||||
}
|
26
app/jbbcode/validators/urlvalidator.class.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
namespace JBBCode\validators;
|
||||
|
||||
defined('PROJECT_PATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* An InputValidator for urls. This can be used to make [url] bbcodes secure.
|
||||
*
|
||||
* @author jbowens
|
||||
* @since May 2013
|
||||
*/
|
||||
class UrlValidator implements \JBBCode\InputValidator
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns true iff $input is a valid url.
|
||||
*
|
||||
* @param $input the string to validate
|
||||
*/
|
||||
public function validate($input)
|
||||
{
|
||||
$valid = filter_var($input, FILTER_VALIDATE_URL);
|
||||
return !!$valid;
|
||||
}
|
||||
|
||||
}
|
60
app/jbbcode/visitors/nestlimitvisitor.class.php
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
namespace JBBCode\visitors;
|
||||
|
||||
defined('PROJECT_PATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* This visitor is used by the jBBCode core to enforce nest limits after
|
||||
* parsing. It traverses the parse graph depth first, removing any subtrees
|
||||
* that are nested deeper than an element's code definition allows.
|
||||
*
|
||||
* @author jbowens
|
||||
* @since May 2013
|
||||
*/
|
||||
class NestLimitVisitor implements \JBBCode\NodeVisitor
|
||||
{
|
||||
|
||||
/* A map from tag name to current depth. */
|
||||
protected $depth = array();
|
||||
|
||||
public function visitDocumentElement(\JBBCode\DocumentElement $documentElement)
|
||||
{
|
||||
foreach($documentElement->getChildren() as $child) {
|
||||
$child->accept($this);
|
||||
}
|
||||
}
|
||||
|
||||
public function visitTextNode(\JBBCode\TextNode $textNode)
|
||||
{
|
||||
/* Nothing to do. Text nodes don't have tag names or children. */
|
||||
}
|
||||
|
||||
public function visitElementNode(\JBBCode\ElementNode $elementNode)
|
||||
{
|
||||
$tagName = strtolower($elementNode->getTagName());
|
||||
|
||||
/* Update the current depth for this tag name. */
|
||||
if (isset($this->depth[$tagName])) {
|
||||
$this->depth[$tagName]++;
|
||||
} else {
|
||||
$this->depth[$tagName] = 1;
|
||||
}
|
||||
|
||||
/* Check if $elementNode is nested too deeply. */
|
||||
if ($elementNode->getCodeDefinition()->getNestLimit() != -1 &&
|
||||
$elementNode->getCodeDefinition()->getNestLimit() < $this->depth[$tagName]) {
|
||||
/* This element is nested too deeply. We need to remove it and not visit any
|
||||
* of its children. */
|
||||
$elementNode->getParent()->removeChild($elementNode);
|
||||
} else {
|
||||
/* This element is not nested too deeply. Visit all of its children. */
|
||||
foreach ($elementNode->getChildren() as $child) {
|
||||
$child->accept($this);
|
||||
}
|
||||
}
|
||||
|
||||
/* Now that we're done visiting this node, decrement the depth. */
|
||||
$this->depth[$tagName]--;
|
||||
}
|
||||
|
||||
}
|
28
app/lang.class.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
defined('PROJECT_PATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Lang
|
||||
{
|
||||
const PATH = 'lang/';
|
||||
|
||||
private static $_dictionary = null;
|
||||
|
||||
public static function load($lang = 'en'){
|
||||
$lang_file = APP_PATH.self::PATH.$lang.'.ini';
|
||||
if(preg_match('/^[a-z]+$/', $lang) && is_readable($lang_file)){
|
||||
self::$_dictionary = parse_ini_file($lang_file);
|
||||
}
|
||||
}
|
||||
|
||||
public static function get($key){
|
||||
if(is_null(self::$_dictionary) || !array_key_exists($key, self::$_dictionary)){
|
||||
return $key;
|
||||
}
|
||||
|
||||
return self::$_dictionary[$key];
|
||||
}
|
||||
}
|
||||
|
||||
function __($key){
|
||||
return Lang::get($key);
|
||||
}
|
67
app/lang/bs.ini
Normal file
|
@ -0,0 +1,67 @@
|
|||
; index.html
|
||||
Show More = "Prikaži još"
|
||||
|
||||
Login = "Prijava"
|
||||
Logout = "Odjava"
|
||||
|
||||
Nick = "Nadimak"
|
||||
Password = "Šifra"
|
||||
Cancel = "Zatvori"
|
||||
|
||||
Post = "Objavi"
|
||||
|
||||
Edit Post = "Izmijeni Objavu"
|
||||
Change Date = "Promijeni Datum"
|
||||
Hide from Timeline = "Sakrij sa Vremenske Linije"
|
||||
Show on Timeline = "Prikaži na Vremenskoj Liniji"
|
||||
Delete Post = "Izbriši objavu"
|
||||
|
||||
Drag photos here = "Privuci fotografije ovdje"
|
||||
Drop photos here = "Privuci fotografije ovdje"
|
||||
What's on your mind? = "Šta vam je na umu?"
|
||||
Feeling = "Osjećaj"
|
||||
How are you feeling? = "Kako se osjećate?"
|
||||
With = "Sa"
|
||||
Who are you with? = "S kim ste?"
|
||||
At = "Gdje"
|
||||
Where are you? = "Gdje se nalazite?"
|
||||
Save = "Sačuvaj"
|
||||
|
||||
January = "Januar"
|
||||
February = "Februar"
|
||||
March = "Mart"
|
||||
April = "April"
|
||||
May = "Maj"
|
||||
June = "Juni"
|
||||
July = "Juli"
|
||||
August = "Avgust"
|
||||
September = "Septembar"
|
||||
October = "Oktobar"
|
||||
November = "Novembar"
|
||||
December = "Decembar"
|
||||
|
||||
Time: = "Vrijeme:"
|
||||
Hour: = "Sati:"
|
||||
Minute: = "Minute:"
|
||||
|
||||
This post will be deleted and you'll no longer be able to find it. You can also edit this post if you just want to change something. = "Ova će objava biti izbrisana i nećete je više moći pronaći. Takođe možete izmijeniti ovu objavu ako želite izvršiti izmjene."
|
||||
|
||||
with = "sa"
|
||||
here: = "ovdje:"
|
||||
|
||||
Public = "Javno"
|
||||
Friends = "Prijatelji"
|
||||
Only me = "Samo ja"
|
||||
|
||||
Show hidden content = "Prikaži skriveni sadržaj"
|
||||
Show all posts = "Prikaži sve objave"
|
||||
|
||||
; user.class.php
|
||||
You are already logged in. = "Već ste prijavljeni."
|
||||
The nick or password is incorrect. = "Nadimak ili šifra su pogrešni."
|
||||
You can't log out. There is no account. = "Ne možete se odjaviti. Račun ne postoji."
|
||||
You are not even logged in. = "Niste čak ni prijavljeni."
|
||||
|
||||
; post.class.php
|
||||
You need to be logged in to perform this action. = "Morate biti priavljeni da biste izvršili ovu radnju."
|
||||
No data. = "Nema podataka."
|
67
app/lang/cz.ini
Normal file
|
@ -0,0 +1,67 @@
|
|||
; index.html
|
||||
Show More = "Zobrazit více"
|
||||
|
||||
Login = "Přihlásit se"
|
||||
Logout = "Odhlásit se"
|
||||
|
||||
Nick = "Přihlašovací jméno"
|
||||
Password = "Heslo"
|
||||
Cancel = "Zrušit"
|
||||
|
||||
Post = "Nový příspěvek"
|
||||
|
||||
Edit Post = "Upravit příspěvek"
|
||||
Change Date = "Změnit datum"
|
||||
Hide from Timeline = "Skrýt na časové ose"
|
||||
Show on Timeline = "Zobrazit na časové ose"
|
||||
Delete Post = "Odstranit příspěvek"
|
||||
|
||||
Drag photos here = "Sem přesuňte fotografie"
|
||||
Drop photos here = "Zde vložte fotografie"
|
||||
What's on your mind? = "Na co myslíš?"
|
||||
Feeling = "Pocit"
|
||||
How are you feeling? = "Jak se cítíš?"
|
||||
With = "Spolu s"
|
||||
Who are you with? = "S kým jsi?"
|
||||
At = "Místo"
|
||||
Where are you? = "Kde jsi?"
|
||||
Save = "Uložit"
|
||||
|
||||
January = "Leden"
|
||||
February = "Únor"
|
||||
March = "Březen"
|
||||
April = "Duben"
|
||||
May = "Květen"
|
||||
June = "Červen"
|
||||
July = "Červenec"
|
||||
August = "Srpen"
|
||||
September = "Září"
|
||||
October = "Říjen"
|
||||
November = "Listopad"
|
||||
December = "Prosinec"
|
||||
|
||||
Time: = "Čas:"
|
||||
Hour: = "Hodina:"
|
||||
Minute: = "Minuta:"
|
||||
|
||||
This post will be deleted and you'll no longer be able to find it. You can also edit this post if you just want to change something. = "Tento příspěvek bude odstraněn a už ho nebude možné najít. Pokud chcete něco změnit, můžete tento příspěvek také upravit."
|
||||
|
||||
with = "s"
|
||||
here: = "zde:"
|
||||
|
||||
Public = "Veřejné"
|
||||
Friends = "Přátelé"
|
||||
Only me = "Jen já"
|
||||
|
||||
Show hidden content = "Zobrazit skrytý obsah"
|
||||
Show all posts = "Zobrazit všechny příspěvky"
|
||||
|
||||
; user.class.php
|
||||
You are already logged in. = "Už jsi přihlášený."
|
||||
The nick or password is incorrect. = "Přihlašovací jméno nebo heslo je nesprávné."
|
||||
You can't log out. There is no account. = "Nemůžeš se odhlásit. Neexistuje žádný účet."
|
||||
You are not even logged in. = "Nejsi ani přihlášený."
|
||||
|
||||
; post.class.php
|
||||
You need to be logged in to perform this action. = "Na provedení této akce musíš být přihlášený."
|
||||
No data. = "Žádná data."
|
67
app/lang/de.ini
Normal file
|
@ -0,0 +1,67 @@
|
|||
; index.html
|
||||
Show More = "Mehr anzeigen"
|
||||
|
||||
Login = "Anmelden"
|
||||
Logout = "Abmelden"
|
||||
|
||||
Nick = "Benutzername"
|
||||
Password = "Kennwort"
|
||||
Cancel = "Abbrechen"
|
||||
|
||||
Post = "Verfasse einen Beitrag"
|
||||
|
||||
Edit Post = "Beitrag bearbeiten"
|
||||
Change Date = "Datum ändern"
|
||||
Hide from Timeline = "In der Chronik verbergen"
|
||||
Show on Timeline = "In der Chronik anzeigen"
|
||||
Delete Post = "Beitrag löschen"
|
||||
|
||||
Drag photos here = "Fotos hierher ziehen"
|
||||
Drop photos here = "Fotos hierher ablegen"
|
||||
What's on your mind? = "Was machst du gerade?"
|
||||
Feeling = "Fühlen"
|
||||
How are you feeling? = "Wie fühlst du dich?"
|
||||
With = "Mit"
|
||||
Who are you with? = "Wer begleitet dich?"
|
||||
At = "Hier"
|
||||
Where are you? = "Wo bist du?"
|
||||
Save = "Speichern"
|
||||
|
||||
January = "Januar"
|
||||
February = "Februar"
|
||||
March = "März"
|
||||
April = "April"
|
||||
May = "Mai"
|
||||
June = "Juni"
|
||||
July = "Juli"
|
||||
August = "August"
|
||||
September = "September"
|
||||
October = "Oktober"
|
||||
November = "November"
|
||||
December = "Dezember"
|
||||
|
||||
Time: = "Zeit:"
|
||||
Hour: = "Stunde:"
|
||||
Minute: = "Minute:"
|
||||
|
||||
This post will be deleted and you'll no longer be able to find it. You can also edit this post if you just want to change something. = "Dieser Beitrag wird gelöscht und du wirst ihn nicht mehr finden können. Du kannst den Beitrag auch bearbeiten, wenn du nur etwas ändern möchtest."
|
||||
|
||||
with = "mit"
|
||||
here: = "hier:"
|
||||
|
||||
Public = "Öffentlich"
|
||||
Friends = "Freunde"
|
||||
Only me = "Nur ich"
|
||||
|
||||
Show hidden content = "Verborgenen Inhalt anzeigen"
|
||||
Show all posts = "Alle Beiträge anzeigen"
|
||||
|
||||
; user.class.php
|
||||
You are already logged in. = "Du bist bereits eingeloggt."
|
||||
The nick or password is incorrect. = "Der Benutzername oder das Kennwort ist falsch."
|
||||
You can't log out. There is no account. = "Du kannst dich nicht abmelden. Es gibt kein Konto."
|
||||
You are not even logged in. = "Du bist nicht mal eingeloggt."
|
||||
|
||||
; post.class.php
|
||||
You need to be logged in to perform this action. = "Du musst angemeldet sein, um diese Aktion durchzuführen."
|
||||
No data. = "Keine Daten."
|
67
app/lang/en.ini
Normal file
|
@ -0,0 +1,67 @@
|
|||
; index.html
|
||||
Show More = "Show More"
|
||||
|
||||
Login = "Login"
|
||||
Logout = "Logout"
|
||||
|
||||
Nick = "Nick"
|
||||
Password = "Password"
|
||||
Cancel = "Cancel"
|
||||
|
||||
Post = "Post"
|
||||
|
||||
Edit Post = "Edit Post"
|
||||
Change Date = "Change Date"
|
||||
Hide from Timeline = "Hide from Timeline"
|
||||
Show on Timeline = "Show on Timeline"
|
||||
Delete Post = "Delete Post"
|
||||
|
||||
Drag photos here = "Drag photos here"
|
||||
Drop photos here = "Drop photos here"
|
||||
What's on your mind? = "What's on your mind?"
|
||||
Feeling = "Feeling"
|
||||
How are you feeling? = "How are you feeling?"
|
||||
With = "With"
|
||||
Who are you with? = "Who are you with?"
|
||||
At = "At"
|
||||
Where are you? = "Where are you?"
|
||||
Save = "Save"
|
||||
|
||||
January = "January"
|
||||
February = "February"
|
||||
March = "March"
|
||||
April = "April"
|
||||
May = "May"
|
||||
June = "June"
|
||||
July = "July"
|
||||
August = "August"
|
||||
September = "September"
|
||||
October = "October"
|
||||
November = "November"
|
||||
December = "December"
|
||||
|
||||
Time: = "Time:"
|
||||
Hour: = "Hour:"
|
||||
Minute: = "Minute:"
|
||||
|
||||
This post will be deleted and you'll no longer be able to find it. You can also edit this post if you just want to change something. = "This post will be deleted and you'll no longer be able to find it. You can also edit this post if you just want to change something."
|
||||
|
||||
with = "with"
|
||||
here: = "here:"
|
||||
|
||||
Public = "Public"
|
||||
Friends = "Friends"
|
||||
Only me = "Only me"
|
||||
|
||||
Show hidden content = "Show hidden content"
|
||||
Show all posts = "Show all posts"
|
||||
|
||||
; user.class.php
|
||||
You are already logged in. = "You are already logged in."
|
||||
The nick or password is incorrect. = "The nick or password is incorrect."
|
||||
You can't log out. There is no account. = "You can't log out. There is no account."
|
||||
You are not even logged in. = "You are not even logged in."
|
||||
|
||||
; post.class.php
|
||||
You need to be logged in to perform this action. = "You need to be logged in to perform this action."
|
||||
No data. = "No data."
|
67
app/lang/es.ini
Normal file
|
@ -0,0 +1,67 @@
|
|||
; index.html
|
||||
Show More = "Mostrar más"
|
||||
|
||||
Login = "Iniciar sesión"
|
||||
Logout = "Cerrar sesión"
|
||||
|
||||
Nick = "Apodo"
|
||||
Password = "Contraseña"
|
||||
Cancel = "Cancelar"
|
||||
|
||||
Post = "Publicar"
|
||||
|
||||
Edit Post = "Editar publicación"
|
||||
Change Date = "Cambiar fecha"
|
||||
Hide from Timeline = "Ocultar de la línea de tiempo"
|
||||
Show on Timeline = "Mostrar en la línea de tiempo"
|
||||
Delete Post = "Eliminar publicación"
|
||||
|
||||
Drag photos here = "Arrastra aquí las fotos"
|
||||
Drop photos here = "Suelta aquí las fotos"
|
||||
What's on your mind? = "¿Qué estas pensando?"
|
||||
Feeling = "Sintiendo"
|
||||
How are you feeling? = "¿Como te sientes?"
|
||||
With = "Con"
|
||||
Who are you with? = "¿Con quién estás?"
|
||||
At = "En"
|
||||
Where are you? = "¿Dónde estás?"
|
||||
Save = "Guardar"
|
||||
|
||||
January = "Enero"
|
||||
February = "Febrero"
|
||||
March = "Marzo"
|
||||
April = "Abril"
|
||||
May = "Mayo"
|
||||
June = "Junio"
|
||||
July = "Julio"
|
||||
August = "Agosto"
|
||||
September = "Septiembre"
|
||||
October = "Octubre"
|
||||
November = "Noviembre"
|
||||
December = "Diciembre"
|
||||
|
||||
Time: = "Hora:"
|
||||
Hour: = "Hora:"
|
||||
Minute: = "Minuto:"
|
||||
|
||||
This post will be deleted and you'll no longer be able to find it. You can also edit this post if you just want to change something. = "Esta publicación se eliminará y ya no podrá ser encontrada. También puedes editar esta publicación si solo deseas cambiar algo."
|
||||
|
||||
with = "con"
|
||||
here: = "aqui:"
|
||||
|
||||
Public = "Público"
|
||||
Friends = "Amigos"
|
||||
Only me = "Solo yo"
|
||||
|
||||
Show hidden content = "Mostrar contenido oculto"
|
||||
Show all posts = "Mostrar todas las publicaciones"
|
||||
|
||||
; user.class.php
|
||||
You are already logged in. = "Ya has iniciado sesión."
|
||||
The nick or password is incorrect. = "El apodo o la contraseña son incorrectos."
|
||||
You can't log out. There is no account. = "No puede cerrar sesión. No hay cuenta."
|
||||
You are not even logged in. = "Ni siquiera estás conectado."
|
||||
|
||||
; post.class.php
|
||||
You need to be logged in to perform this action. = "Debe haber iniciado una sesión para realizar esta acción."
|
||||
No data. = "Sin datos."
|
67
app/lang/fr.ini
Normal file
|
@ -0,0 +1,67 @@
|
|||
; index.html
|
||||
Show More = "Voir plus"
|
||||
|
||||
Login = "Connexion"
|
||||
Logout = "Déconnexion"
|
||||
|
||||
Nick = "Pseudo"
|
||||
Password = "Mot de passe"
|
||||
Cancel = "Annuler"
|
||||
|
||||
Post = "Publier"
|
||||
|
||||
Edit Post = "Modifier la publication"
|
||||
Change Date = "Changer la date"
|
||||
Hide from Timeline = "Cacher du mur"
|
||||
Show on Timeline = "Montrer sur le mur"
|
||||
Delete Post = "Supprimer la publication"
|
||||
|
||||
Drag photos here = "Glisser les photos ici"
|
||||
Drop photos here = "Déposer les photos ici"
|
||||
What's on your mind? = "Que souhaitez-vous partager ?"
|
||||
Feeling = "Je me sens"
|
||||
How are you feeling? = "Comment vous sentez-vous ?"
|
||||
With = "Avec"
|
||||
Who are you with? = "Avec qui êtes-vous ?"
|
||||
At = "À"
|
||||
Where are you? = "Où êtes-vous ?"
|
||||
Save = "Enregistrer"
|
||||
|
||||
January = "Janvier"
|
||||
February = "Février"
|
||||
March = "Mars"
|
||||
April = "Avril"
|
||||
May = "Mai"
|
||||
June = "Juin"
|
||||
July = "Juillet"
|
||||
August = "Août"
|
||||
September = "Septembre"
|
||||
October = "Octobre"
|
||||
November = "Novembre"
|
||||
December = "Décembre"
|
||||
|
||||
Time: = "Heure :"
|
||||
Hour: = "Heure :"
|
||||
Minute: = "Minutes :"
|
||||
|
||||
This post will be deleted and you'll no longer be able to find it. You can also edit this post if you just want to change something. = "Cette publication sera supprimée et vous ne pourrez plus la retrouver. Vous pouvez aussi la modifier si vous souhaitez simplement changer quelque chose."
|
||||
|
||||
with = "avec"
|
||||
here: = "à"
|
||||
|
||||
Public = "Publique"
|
||||
Friends = "Amis"
|
||||
Only me = "Seulement moi"
|
||||
|
||||
Show hidden content = "Montrer le contenu caché"
|
||||
Show all posts = "Montrer toutes les publications"
|
||||
|
||||
; user.class.php
|
||||
You are already logged in. = "Vous êtes déjà connecté."
|
||||
The nick or password is incorrect. = "Votre pseudo ou mot de passe est incorrect."
|
||||
You can't log out. There is no account. = "Vous ne pouvez pas vous déconnecter, les comptes sont désactivés."
|
||||
You are not even logged in. = "Vous n’êtes pas connecté."
|
||||
|
||||
; post.class.php
|
||||
You need to be logged in to perform this action. = "Vous devez être connecté pour pouvoir faire ça."
|
||||
No data. = "Aucune données."
|
67
app/lang/nl.ini
Normal file
|
@ -0,0 +1,67 @@
|
|||
; index.html
|
||||
Show More = "Verder Lezen"
|
||||
|
||||
Login = "Aanmelden"
|
||||
Logout = "Afmelden"
|
||||
|
||||
Nick = "Gebruiker"
|
||||
Password = "Wachtwoord"
|
||||
Cancel = "Annuleren"
|
||||
|
||||
Post = "Bericht"
|
||||
|
||||
Edit Post = "Wijzig Bericht"
|
||||
Change Date = "Wijzig Datum"
|
||||
Hide from Timeline = "Verbergen van Tijdlijn"
|
||||
Show on Timeline = "Laten zien op Tijdlijn"
|
||||
Delete Post = "Verwijder Bericht"
|
||||
|
||||
Drag photos here = "Sleep foto's hier"
|
||||
Drop photos here = "Gooi foto's hier"
|
||||
What's on your mind? = "Waar ben je mee bezig?"
|
||||
Feeling = "Gevoel"
|
||||
How are you feeling? = "Hoe voel je je?"
|
||||
With = "Met"
|
||||
Who are you with? = "Met wie ben je?"
|
||||
At = "Bij"
|
||||
Where are you? = "Waar ben je?"
|
||||
Save = "Opslaan"
|
||||
|
||||
January = "Januari"
|
||||
February = "Februari"
|
||||
March = "Maart"
|
||||
April = "April"
|
||||
May = "Mei"
|
||||
June = "Juni"
|
||||
July = "Juli"
|
||||
August = "Augustus"
|
||||
September = "September"
|
||||
October = "Oktober"
|
||||
November = "November"
|
||||
December = "December"
|
||||
|
||||
Time: = "Tijd:"
|
||||
Hour: = "Uur:"
|
||||
Minute: = "Minuten:"
|
||||
|
||||
This post will be deleted and you'll no longer be able to find it. You can also edit this post if you just want to change something. = "Dit bericht word verwijderd en kan niet meer worden gevonden. Je kan ook het bericht wijzigen als je dat liever wilt."
|
||||
|
||||
with = "met"
|
||||
here: = "Bij:"
|
||||
|
||||
Public = "Openbaar"
|
||||
Friends = "Vrienden"
|
||||
Only me = "Alleen ik"
|
||||
|
||||
Show hidden content = "Laat verborgen berichten zien"
|
||||
Show all posts = "Alle berichten zien"
|
||||
|
||||
; user.class.php
|
||||
You are already logged in. = "Je bent al ingelogt."
|
||||
The nick or password is incorrect. = "De gebruiken of het Wachtwoord is onjuist."
|
||||
You can't log out. There is no account. = "Je kan niet Afmelden. Er is geen Account."
|
||||
You are not even logged in. = "Je ben niet eens ingelogt."
|
||||
|
||||
; post.class.php
|
||||
You need to be logged in to perform this action. = "Je moet ingelogged zijn om deze actie uit te voeren."
|
||||
No data. = "Geen data."
|
67
app/lang/ru.ini
Normal file
|
@ -0,0 +1,67 @@
|
|||
; index.html
|
||||
Show More = "Показать больше"
|
||||
|
||||
Login = "Войти"
|
||||
Logout = "Выйти"
|
||||
|
||||
Nick = "Логин"
|
||||
Password = "Пароль"
|
||||
Cancel = "Отмена"
|
||||
|
||||
Post = "Пост"
|
||||
|
||||
Edit Post = "Редактировать пост"
|
||||
Change Date = "Изменить дату"
|
||||
Hide from Timeline = "Скрыть из ленты"
|
||||
Show on Timeline = "Показать в ленте"
|
||||
Delete Post = "Удалить пост"
|
||||
|
||||
Drag photos here = "Перетащите сюда фото"
|
||||
Drop photos here = "Оставь фото здесь"
|
||||
What's on your mind? = "О чем ты думаешь?"
|
||||
Feeling = "Ощущения"
|
||||
How are you feeling? = "Как ты себя чувствуешь?"
|
||||
With = "В компании"
|
||||
Who are you with? = "С кем ты?"
|
||||
At = "Локация"
|
||||
Where are you? = "Где ты?"
|
||||
Save = "Сохранить"
|
||||
|
||||
January = "Январь"
|
||||
February = "Февраль"
|
||||
March = "Март"
|
||||
April = "Апрель"
|
||||
May = "Май"
|
||||
June = "Июнь"
|
||||
July = "Июль"
|
||||
August = "Август"
|
||||
September = "Сентябрь"
|
||||
October = "Октябрь"
|
||||
November = "Ноябрь"
|
||||
December = "Декабрь"
|
||||
|
||||
Time: = "Время:"
|
||||
Hour: = "Чаc:"
|
||||
Minute: = "Минута:"
|
||||
|
||||
This post will be deleted and you'll no longer be able to find it. You can also edit this post if you just want to change something. = "Этот пост будет удален, и вы больше не сможете его найти. Вы также можете отредактировать этот пост, если просто хотите что-то изменить"
|
||||
|
||||
with = "с"
|
||||
here: = "здесь:"
|
||||
|
||||
Public = "Публичный"
|
||||
Friends = "Друзья"
|
||||
Only me = "Только я"
|
||||
|
||||
Show hidden content = "Показать скрытый контент"
|
||||
Show all posts = "Показать все посты"
|
||||
|
||||
; user.class.php
|
||||
You are already logged in. = "Вы уже залогинены."
|
||||
The nick or password is incorrect. = "Логин или пароль неверный."
|
||||
You can't log out. There is no account. = "Вы не можете выйти. Вы не залогинены."
|
||||
You are not even logged in. = "Вы не авторизовались."
|
||||
|
||||
; post.class.php
|
||||
You need to be logged in to perform this action. = "Вы должны быть залогинены, чтобы выполнить это действие."
|
||||
No data. = "Нет данных."
|
67
app/lang/sk.ini
Normal file
|
@ -0,0 +1,67 @@
|
|||
; index.html
|
||||
Show More = "Zobraziť viac"
|
||||
|
||||
Login = "Prihlásiť sa"
|
||||
Logout = "Odhlásiť sa"
|
||||
|
||||
Nick = "Prihlasovacie meno"
|
||||
Password = "Heslo"
|
||||
Cancel = "Zrušiť"
|
||||
|
||||
Post = "Nový príspevok"
|
||||
|
||||
Edit Post = "Upraviť príspevok"
|
||||
Change Date = "Zmeniť dátum"
|
||||
Hide from Timeline = "Skryť na časovej osi"
|
||||
Show on Timeline = "Zobraziť na časovej osi"
|
||||
Delete Post = "Odstrániť príspevok"
|
||||
|
||||
Drag photos here = "Sem presuňte fotografie"
|
||||
Drop photos here = "Tu vložte fotografie"
|
||||
What's on your mind? = "Na čo myslíš?"
|
||||
Feeling = "Pocit"
|
||||
How are you feeling? = "Ako sa cítiš?"
|
||||
With = "Spolu s"
|
||||
Who are you with? = "S kým si?"
|
||||
At = "Miesto"
|
||||
Where are you? = "Kde si?"
|
||||
Save = "Uložiť"
|
||||
|
||||
January = "Január"
|
||||
February = "Február"
|
||||
March = "Marec"
|
||||
April = "Apríl"
|
||||
May = "Máj"
|
||||
June = "Jún"
|
||||
July = "Júl"
|
||||
August = "August"
|
||||
September = "September"
|
||||
October = "Október"
|
||||
November = "November"
|
||||
December = "December"
|
||||
|
||||
Time: = "Čas:"
|
||||
Hour: = "Hodina:"
|
||||
Minute: = "Minúta:"
|
||||
|
||||
This post will be deleted and you'll no longer be able to find it. You can also edit this post if you just want to change something. = "Tento príspevok bude odstránený a už ho nebudete môcť nájsť. Tento príspevok môžete tiež upraviť, ak chcete niečo zmeniť."
|
||||
|
||||
with = "s"
|
||||
here: = "tu:"
|
||||
|
||||
Public = "Verejné"
|
||||
Friends = "Priatelia"
|
||||
Only me = "Iba ja"
|
||||
|
||||
Show hidden content = "Zobraziť skrytý obsah"
|
||||
Show all posts = "Zobraziť všetky príspevky"
|
||||
|
||||
; user.class.php
|
||||
You are already logged in. = "Už si prihlásený."
|
||||
The nick or password is incorrect. = "Prihlasovacie meno alebo heslo je nesprávne."
|
||||
You can't log out. There is no account. = "Nemôžeš sa odhlásiť. Neexistuje žiadny účet."
|
||||
You are not even logged in. = "Nie si ani prihlásený."
|
||||
|
||||
; post.class.php
|
||||
You need to be logged in to perform this action. = "Na vykonanie tejto akcie musíš byť prihlásený."
|
||||
No data. = "Žiadne dáta."
|
40
app/log.class.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
defined('PROJECT_PATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Log
|
||||
{
|
||||
private static $_files = [
|
||||
"ajax_access",
|
||||
"ajax_errors",
|
||||
"login_fails",
|
||||
"visitors"
|
||||
];
|
||||
|
||||
public static function put($_file, $_text = null){
|
||||
if(!Config::get_safe("logs", false) || !in_array($_file, static::$_files)){
|
||||
return ;
|
||||
}
|
||||
|
||||
$_logs_path = Config::get('logs_path');
|
||||
if(!is_dir($_logs_path) && !mkdir($_logs_path, 755, true)){
|
||||
die("Logs directory could not be created.");
|
||||
}
|
||||
|
||||
if(false === file_put_contents($_logs_path.$_file.".log", self::line($_text), FILE_APPEND) && Config::get_safe('debug', false)){
|
||||
die(sprintf("Can't write to %s.log file.", $_file));
|
||||
}
|
||||
}
|
||||
|
||||
private static function escape($_text = null){
|
||||
return preg_replace("/[\n\r\t]/", "-", $_text);
|
||||
}
|
||||
|
||||
private static function line($_text = null){
|
||||
return trim(
|
||||
date('Y-m-d H:i:s')."\t".
|
||||
self::escape($_SERVER["REMOTE_ADDR"])."\t".
|
||||
self::escape($_SERVER["HTTP_USER_AGENT"])."\t".
|
||||
self::escape($_text)
|
||||
).PHP_EOL;
|
||||
}
|
||||
}
|
469
app/post.class.php
Normal file
|
@ -0,0 +1,469 @@
|
|||
<?php
|
||||
defined('PROJECT_PATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Post
|
||||
{
|
||||
private static function login_protected(){
|
||||
if(!User::is_logged_in()){
|
||||
throw new Exception(__("You need to be logged in to perform this action."));
|
||||
}
|
||||
}
|
||||
|
||||
private static function parse_content($c){
|
||||
$parser = new JBBCode\Parser();
|
||||
$parser->addCodeDefinitionSet(new JBBCode\DefaultCodeDefinitionSet());
|
||||
|
||||
if(Config::get("highlight")){
|
||||
$c = str_replace("\t", " ", $c);
|
||||
$c = preg_replace("/\[code(?:=([^\[]+))?\]\s*?(?:\n|\r)?/i", '[code=$1]', $c);
|
||||
$c = preg_replace("/\[\/code\]\s*?(?:\n|\r)?/i", '[/code]', $c);
|
||||
|
||||
// Add code definiton
|
||||
$parser->addCodeDefinition(new class extends \JBBCode\CodeDefinition {
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
$this->setTagName("code");
|
||||
$this->setParseContent(false);
|
||||
$this->setUseOption(true);
|
||||
}
|
||||
|
||||
public function asHtml(\JBBCode\ElementNode $el){
|
||||
$content = $this->getContent($el);
|
||||
$class = $el->getAttribute()['code'];
|
||||
return '<code class="'.$class.'">'.htmlentities($content).'</code>';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Custom tags
|
||||
$builder = new JBBCode\CodeDefinitionBuilder("goal", "<div class=\"b_goal star\">{param}</div>");
|
||||
$parser->addCodeDefinition($builder->build());
|
||||
|
||||
$builder = new JBBCode\CodeDefinitionBuilder("goal", "<div class=\"b_goal {option}\">{param}</div>");
|
||||
$builder->setUseOption(true);
|
||||
$parser->addCodeDefinition($builder->build());
|
||||
|
||||
if(($tags = Config::get_safe("bbtags", [])) && !empty($tags)){
|
||||
foreach($tags as $tag => $content){
|
||||
$builder = new JBBCode\CodeDefinitionBuilder($tag, $content);
|
||||
$parser->addCodeDefinition($builder->build());
|
||||
}
|
||||
}
|
||||
|
||||
$parser->parse($c);
|
||||
|
||||
// Visit every text node
|
||||
$parser->accept(new class implements \JBBCode\NodeVisitor{
|
||||
function visitDocumentElement(\JBBCode\DocumentElement $documentElement){
|
||||
foreach($documentElement->getChildren() as $child) {
|
||||
$child->accept($this);
|
||||
}
|
||||
}
|
||||
|
||||
function visitTextNode(\JBBCode\TextNode $textNode){
|
||||
$c = $textNode->getValue();
|
||||
$c = preg_replace('/\"([^\"]+)\"/i', "„$1\"", $c);
|
||||
$c = htmlentities($c);
|
||||
$c = preg_replace('/\*([^\*]+)\*/i', "<strong>$1</strong>", $c);
|
||||
$c = preg_replace('/(https?\:\/\/[^\" \n]+)/i', "<a href=\"\\0\" target=\"_blank\">\\0</a>", $c);
|
||||
$c = preg_replace('/(\#[A-Za-z0-9-_]+)(\s|$)/i', "<span class=\"tag\">\\1</span>\\2", $c);
|
||||
$c = nl2br($c);
|
||||
$textNode->setValue($c);
|
||||
}
|
||||
|
||||
function visitElementNode(\JBBCode\ElementNode $elementNode){
|
||||
/* We only want to visit text nodes within elements if the element's
|
||||
* code definition allows for its content to be parsed.
|
||||
*/
|
||||
if ($elementNode->getCodeDefinition()->parseContent()) {
|
||||
foreach ($elementNode->getChildren() as $child) {
|
||||
$child->accept($this);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return $parser->getAsHtml();
|
||||
}
|
||||
|
||||
private static function raw_data($raw_input){
|
||||
$default_input = [
|
||||
"text" => '',
|
||||
"plain_text" => '',
|
||||
"feeling" => '',
|
||||
"persons" => '',
|
||||
"location" => '',
|
||||
"content_type" => '',
|
||||
"content" => '',
|
||||
"privacy" => ''
|
||||
];
|
||||
|
||||
// Handle only allowed keys
|
||||
$raw_output = array();
|
||||
foreach($default_input as $key => $def){
|
||||
// Key exists in input
|
||||
if(array_key_exists($key, $raw_input)){
|
||||
$raw_output[$key] = $raw_input[$key];
|
||||
} else {
|
||||
$raw_output[$key] = $default_input[$key];
|
||||
}
|
||||
}
|
||||
|
||||
if($raw_output['privacy'] != "public" && $raw_output['privacy'] != "friends"){
|
||||
$raw_output['privacy'] = "private";
|
||||
}
|
||||
|
||||
return $raw_output;
|
||||
}
|
||||
|
||||
public static function insert($r){
|
||||
self::login_protected();
|
||||
|
||||
$data = self::raw_data($r);
|
||||
|
||||
if(empty($data['text'])){
|
||||
throw new Exception(__("No data."));
|
||||
}
|
||||
|
||||
$data['plain_text'] = $data['text'];
|
||||
$data['text'] = self::parse_content($data['text']);
|
||||
$data['datetime'] = 'NOW()';
|
||||
$data['status'] = '1';
|
||||
|
||||
$data['id'] = DB::get_instance()->insert('posts', $data)->last_id();
|
||||
|
||||
$data['datetime'] = date("d M Y H:i");
|
||||
unset($data['plain_text']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function update($r){
|
||||
self::login_protected();
|
||||
|
||||
$data = self::raw_data($r);
|
||||
|
||||
$data['plain_text'] = $data['text'];
|
||||
$data['text'] = self::parse_content($data['text']);
|
||||
|
||||
DB::get_instance()->update('posts', $data, "WHERE `id` = ? AND `status` <> 5", $r["id"]);
|
||||
|
||||
unset($data['plain_text']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function hide($r){
|
||||
self::login_protected();
|
||||
|
||||
DB::get_instance()->query("
|
||||
UPDATE `posts`
|
||||
SET `status` = 4
|
||||
WHERE `id` = ?
|
||||
AND `status` <> 5
|
||||
", $r["id"]);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function show($r){
|
||||
self::login_protected();
|
||||
|
||||
DB::get_instance()->query("
|
||||
UPDATE `posts`
|
||||
SET `status` = 1
|
||||
WHERE `id` = ?
|
||||
AND `status` <> 5
|
||||
", $r["id"]);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function delete($r){
|
||||
self::login_protected();
|
||||
|
||||
DB::get_instance()->query("
|
||||
UPDATE `posts`
|
||||
SET `status` = 5
|
||||
WHERE `id` = ?
|
||||
", $r["id"]);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function edit_data($r){
|
||||
self::login_protected();
|
||||
|
||||
return DB::get_instance()->query("
|
||||
SELECT `plain_text`, `feeling`, `persons`, `location`, `privacy`, `content_type`, `content`
|
||||
FROM `posts`
|
||||
WHERE `id` = ?
|
||||
AND `status` <> 5
|
||||
", $r["id"])->first();
|
||||
}
|
||||
|
||||
public static function get_date($r){
|
||||
self::login_protected();
|
||||
|
||||
if (DB::connection() === 'sqlite') {
|
||||
$datetime = "strftime('%Y %m %d %H %M', `posts`.`datetime`)";
|
||||
} else if (DB::connection() === 'postgres') {
|
||||
$datetime = "to_char(datetime,'YYYY MM DD HH24 MI')";
|
||||
} else {
|
||||
$datetime = "DATE_FORMAT(`datetime`,'%Y %c %e %k %i')";
|
||||
}
|
||||
|
||||
$date = DB::get_instance()->query("
|
||||
SELECT $datetime AS `date_format`
|
||||
FROM `posts`
|
||||
WHERE `id` = ?
|
||||
AND `status` <> 5
|
||||
", $r["id"])->first("date_format");
|
||||
$date = array_map("intval", explode(" ", $date));
|
||||
$date[4] = floor($date[4]/10)*10;
|
||||
return $date;
|
||||
}
|
||||
|
||||
public static function set_date($r){
|
||||
self::login_protected();
|
||||
|
||||
$d = $r["date"];
|
||||
if (DB::connection() === 'sqlite') {
|
||||
$datetime = vsprintf("%04d-%02d-%02d %02d:%02d", $d);
|
||||
} else {
|
||||
$datetime = vsprintf("%04d/%02d/%02d %02d:%02d", $d);
|
||||
}
|
||||
|
||||
DB::get_instance()->query("
|
||||
UPDATE `posts`
|
||||
SET `datetime` = ?
|
||||
WHERE `id` = ?
|
||||
AND `status` <> 5
|
||||
", $datetime, $r["id"]);
|
||||
return [ "datetime" => date("d M Y H:i", strtotime($datetime)) ];
|
||||
}
|
||||
|
||||
public static function parse_link($r){
|
||||
self::login_protected();
|
||||
|
||||
$l = $r["link"];
|
||||
|
||||
preg_match('/^https?:\/\/([^:\/\s]+)([^\/\s]*\/)([^\.\s]+)\.(jpe?g|png|gif)((\?|\#)(.*))?$/i', $l, $img);
|
||||
if($img){
|
||||
return [
|
||||
"valid" => true,
|
||||
"content_type" => "img_link",
|
||||
"content" => [
|
||||
"src" => $l,
|
||||
"host" => $img[1]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
preg_match('/^https?:\/\/(www\.)?([^:\/\s]+)(.*)?$/i', $l, $url);
|
||||
$curl_request_url = $l;
|
||||
|
||||
// Get content
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_ENCODING , "");
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Proxycat/1.1)");
|
||||
curl_setopt($ch, CURLOPT_REFERER, '');
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 7); // 7sec
|
||||
|
||||
// Proxy settings
|
||||
if($proxy = Config::get_safe("proxy", false)){
|
||||
$proxytype = Config::get_safe("proxytype", false);
|
||||
$proxyauth = Config::get_safe("proxyauth", false);
|
||||
if($proxytype === 'URL_PREFIX'){
|
||||
$curl_request_url = $proxy.$curl_request_url;
|
||||
|
||||
if($proxyauth){
|
||||
curl_setopt($ch, CURLOPT_USERPWD, $proxyauth);
|
||||
}
|
||||
} else {
|
||||
curl_setopt($ch, CURLOPT_PROXY, $proxy);
|
||||
|
||||
if($proxyauth){
|
||||
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
|
||||
}
|
||||
|
||||
switch ($proxytype) {
|
||||
case 'CURLPROXY_SOCKS4':
|
||||
$proxytype = CURLPROXY_SOCKS4;
|
||||
break;
|
||||
case 'CURLPROXY_SOCKS5':
|
||||
$proxytype = CURLPROXY_SOCKS5;
|
||||
break;
|
||||
case 'CURLPROXY_HTTP':
|
||||
default:
|
||||
$proxytype = CURLPROXY_HTTP;
|
||||
break;
|
||||
}
|
||||
|
||||
curl_setopt($ch, CURLOPT_PROXYTYPE, $proxytype);
|
||||
}
|
||||
}
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, $curl_request_url);
|
||||
$html = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
// Parse
|
||||
$doc = new DOMDocument();
|
||||
@$doc->loadHTML('<?xml encoding="utf-8" ?>'.$html);
|
||||
|
||||
// Get title
|
||||
$nodes = $doc->getElementsByTagName('title');
|
||||
$title = $nodes->item(0)->nodeValue;
|
||||
|
||||
// Content
|
||||
$content = [
|
||||
"link" => $l,
|
||||
"title" => ($title ? $title : $url[2]),
|
||||
"is_video" => false,
|
||||
"host" => $url[2]
|
||||
];
|
||||
|
||||
// Metas
|
||||
$metas = $doc->getElementsByTagName('meta');
|
||||
for($i = 0; $i < $metas->length; $i++){
|
||||
$meta = $metas->item($i);
|
||||
|
||||
$n = $meta->getAttribute('name');
|
||||
$p = $meta->getAttribute('property');
|
||||
$c = $meta->getAttribute('content');
|
||||
|
||||
if($n == 'twitter:description' || $p == 'og:description' || $n == 'description'){
|
||||
$content["desc"] = substr($c, 0, 180);
|
||||
}
|
||||
|
||||
if($n == 'twitter:title' || $p == 'og:title' || $p == 'title'){
|
||||
$content["title"] = $c;
|
||||
}
|
||||
|
||||
if($p == 'og:url'){
|
||||
$content["link"] = $c;
|
||||
}
|
||||
|
||||
if($p == 'og:type'){
|
||||
$content["is_video"] = (preg_match("/video/", $c));
|
||||
}
|
||||
|
||||
if($n == 'twitter:image:src' || $p == 'og:image'){
|
||||
// Absolute url
|
||||
if(preg_match("/^(https?:)?\/\//", $c)) {
|
||||
$content["thumb"] = $c;
|
||||
}
|
||||
|
||||
// Relative url from root
|
||||
elseif(preg_match("/^\//", $c)) {
|
||||
preg_match("/^((?:https?:)?\/\/([^\/]+))(\/|$)/", $l, $m);
|
||||
$content["thumb"] = $m[1].'/'.$c;
|
||||
}
|
||||
|
||||
// Relative url from current directory
|
||||
else {
|
||||
preg_match("/^((?:https?:)?\/\/[^\/]+.*?)(\/[^\/]*)?$/", $l, $m);
|
||||
$content["thumb"] = $m[1].'/'.$c;
|
||||
}
|
||||
}
|
||||
|
||||
if($n == 'twitter:domain'){
|
||||
$content["host"] = $c;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
"valid" => true,
|
||||
"content_type" => "link",
|
||||
"content" => $content
|
||||
];
|
||||
}
|
||||
|
||||
public static function upload_image(){
|
||||
self::login_protected();
|
||||
|
||||
return Image::upload();
|
||||
}
|
||||
|
||||
public static function load($r){
|
||||
$from = [];
|
||||
if(preg_match("/^[0-9]{4}-[0-9]{2}$/", @$r["filter"]["from"])){
|
||||
$from = $r["filter"]["from"]."-01 00:00";
|
||||
}
|
||||
|
||||
if(preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/", @$r["filter"]["from"])){
|
||||
$from = $r["filter"]["from"]." 00:00";
|
||||
}
|
||||
|
||||
$to = [];
|
||||
if(preg_match("/^[0-9]{4}-[0-9]{2}$/", @$r["filter"]["to"])){
|
||||
$to = $r["filter"]["to"]."-01 00:00";
|
||||
}
|
||||
|
||||
if(preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/", @$r["filter"]["to"])){
|
||||
$to = $r["filter"]["to"]." 00:00";
|
||||
}
|
||||
|
||||
$id = [];
|
||||
if(@$r["filter"]["id"]){
|
||||
$id = intval($r["filter"]["id"]);
|
||||
}
|
||||
|
||||
$tag = [];
|
||||
if(preg_match("/^[A-Za-z0-9-_]+$/", @$r["filter"]["tag"])){
|
||||
$tag = '#'.$r["filter"]["tag"];
|
||||
}
|
||||
|
||||
$loc = [];
|
||||
if(@$r["filter"]["loc"]){
|
||||
$loc = $r["filter"]["loc"];
|
||||
}
|
||||
|
||||
$person = [];
|
||||
if(@$r["filter"]["person"]){
|
||||
$person = $r["filter"]["person"];
|
||||
}
|
||||
|
||||
if (DB::connection() === 'sqlite') {
|
||||
$datetime = "strftime('%d %m %Y %H:%M', `posts`.`datetime`)";
|
||||
} else if (DB::connection() === 'postgres') {
|
||||
$datetime = "to_char(posts.datetime,'DD Mon YYYY HH24:MI')";
|
||||
} else {
|
||||
$datetime = "DATE_FORMAT(`posts`.`datetime`,'%d %b %Y %H:%i')";
|
||||
}
|
||||
|
||||
$like_match = "LIKE ".DB::concat("'%'", "?", "'%'");
|
||||
|
||||
return DB::get_instance()->query("
|
||||
SELECT
|
||||
`id`, `text`, `feeling`, `persons`, `location`, `privacy`, `content_type`, `content`,
|
||||
$datetime AS `datetime`, (`status` <> 1) AS `is_hidden`
|
||||
FROM `posts`
|
||||
WHERE ".
|
||||
(!User::is_logged_in() ? (User::is_visitor() ? "`privacy` IN ('public', 'friends') AND " : "`privacy` = 'public' AND ") : "").
|
||||
($from ? "`posts`.`datetime` > ? AND " : "").
|
||||
($to ? "`posts`.`datetime` < ? AND " : "").
|
||||
($id ? "`id` = ? AND " : "").
|
||||
($tag ? "`plain_text` $like_match AND " : "").
|
||||
($loc ? "`location` $like_match AND " : "").
|
||||
($person ? "`persons` $like_match AND " : "").
|
||||
"`status` <> 5
|
||||
ORDER BY `posts`.`datetime` ".(@$r["sort"] == 'reverse' ? "ASC" : "DESC")."
|
||||
LIMIT ? OFFSET ?
|
||||
", $from, $to, $id, $tag, $loc, $person, $r["limit"], $r["offset"]
|
||||
)->all();
|
||||
}
|
||||
|
||||
public static function login($r){
|
||||
return User::login($r["nick"], $r["pass"]);
|
||||
}
|
||||
|
||||
public static function logout(){
|
||||
return User::logout();
|
||||
}
|
||||
|
||||
public static function handshake($r){
|
||||
return ["logged_in" => User::is_logged_in(), "is_visitor" => User::is_visitor()];
|
||||
}
|
||||
}
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
defined('PROJECT_PATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* SplClassLoader implementation that implements the technical interoperability
|
||||
* standards for PHP 5.3 namespaces and class names.
|
||||
|
@ -22,7 +24,7 @@ class SplClassLoader
|
|||
private $_includePath;
|
||||
private $_namespaceSeparator = '\\';
|
||||
private $_excludeNs;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new <tt>SplClassLoader</tt> that loads classes of the
|
||||
* specified namespace.
|
||||
|
@ -33,7 +35,7 @@ class SplClassLoader
|
|||
$this->_namespace = $ns;
|
||||
$this->_includePath = $includePath;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the namespace separator used by classes in the namespace of this class loader.
|
||||
*
|
||||
|
@ -42,11 +44,11 @@ class SplClassLoader
|
|||
public function setNamespaceSeparator($sep) {
|
||||
$this->_namespaceSeparator = $sep;
|
||||
}
|
||||
|
||||
|
||||
public function setExcludeNs($exclude) {
|
||||
$this->_excludeNs = $exclude;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the namespace seperator used by classes in the namespace of this class loader.
|
||||
*
|
||||
|
@ -55,7 +57,7 @@ class SplClassLoader
|
|||
public function getNamespaceSeparator() {
|
||||
return $this->_namespaceSeparator;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the base include path for all class files in the namespace of this class loader.
|
||||
*
|
||||
|
@ -64,7 +66,7 @@ class SplClassLoader
|
|||
public function setIncludePath($includePath) {
|
||||
$this->_includePath = $includePath;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the base include path for all class files in the namespace of this class loader.
|
||||
*
|
||||
|
@ -73,7 +75,7 @@ class SplClassLoader
|
|||
public function getIncludePath() {
|
||||
return $this->_includePath;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the file extension of class files in the namespace of this class loader.
|
||||
*
|
||||
|
@ -82,7 +84,7 @@ class SplClassLoader
|
|||
public function setFileExtension($fileExtension) {
|
||||
$this->_fileExtension = $fileExtension;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the file extension of class files in the namespace of this class loader.
|
||||
*
|
||||
|
@ -91,21 +93,21 @@ class SplClassLoader
|
|||
public function getFileExtension() {
|
||||
return $this->_fileExtension;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Installs this class loader on the SPL autoload stack.
|
||||
*/
|
||||
public function register() {
|
||||
spl_autoload_register(array($this, 'loadClass'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Uninstalls this class loader from the SPL autoloader stack.
|
||||
*/
|
||||
public function unregister() {
|
||||
spl_autoload_unregister(array($this, 'loadClass'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads the given class or interface.
|
||||
*
|
||||
|
@ -116,27 +118,27 @@ class SplClassLoader
|
|||
if (!empty($this->_excludeNs)) {
|
||||
$className = str_replace($this->_excludeNs, '', $className);
|
||||
}
|
||||
|
||||
|
||||
if (null === $this->_namespace || $this->_namespace.$this->_namespaceSeparator === substr($className, 0, strlen($this->_namespace.$this->_namespaceSeparator))) {
|
||||
$fileName = '';
|
||||
$namespace = '';
|
||||
|
||||
|
||||
if (false !== ($lastNsPos = strripos($className, $this->_namespaceSeparator))) {
|
||||
$namespace = substr($className, 0, $lastNsPos);
|
||||
$className = substr($className, $lastNsPos + 1);
|
||||
$fileName = str_replace($this->_namespaceSeparator, DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
|
||||
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . $this->_fileExtension;
|
||||
|
||||
|
||||
$fileName = strtolower($fileName);
|
||||
|
||||
|
||||
$full = ($this->_includePath !== null ? $this->_includePath . DIRECTORY_SEPARATOR : '') . $fileName;
|
||||
|
||||
|
||||
if (!file_exists($full)) {
|
||||
throw new Exception("Class file for '".$className."' not found");
|
||||
throw new Exception(sprintf('Class file for "%s" not found.', $className));
|
||||
}
|
||||
|
||||
|
||||
require $full;
|
||||
}
|
||||
}
|
64
app/user.class.php
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
defined('PROJECT_PATH') OR exit('No direct script access allowed');
|
||||
|
||||
class user
|
||||
{
|
||||
const SESSION_NAME = "logged_in";
|
||||
|
||||
public static function is_visitor(){
|
||||
if(!Config::get_safe("force_login", false)){
|
||||
return true;
|
||||
}
|
||||
|
||||
return !empty($_SESSION[User::SESSION_NAME]) && $_SESSION[User::SESSION_NAME] === 'visitor';
|
||||
}
|
||||
|
||||
public static function is_logged_in(){
|
||||
if(!Config::get_safe("force_login", false)){
|
||||
return true;
|
||||
}
|
||||
|
||||
return !empty($_SESSION[User::SESSION_NAME]) && $_SESSION[User::SESSION_NAME] === hash("crc32", Config::get("nick").Config::get_safe("pass", ""), false);
|
||||
}
|
||||
|
||||
public static function login($nick, $pass){
|
||||
if(!Config::get_safe("force_login", false)){
|
||||
return true;
|
||||
}
|
||||
|
||||
if(self::is_logged_in()){
|
||||
throw new Exception(__("You are already logged in."));
|
||||
}
|
||||
|
||||
if(Config::get("nick") === $nick && Config::get_safe("pass", "") === $pass){
|
||||
$_SESSION[User::SESSION_NAME] = hash("crc32", $nick.$pass, false);
|
||||
return ["logged_in" => true, "is_visitor" => false];
|
||||
}
|
||||
|
||||
// Legacy: Visitors and Friends.
|
||||
$visitors = array_merge(
|
||||
Config::get_safe("friends", []),
|
||||
Config::get_safe("visitor", [])
|
||||
);
|
||||
if(!empty($visitors) && isset($visitors[$nick]) && $visitors[$nick] === $pass){
|
||||
$_SESSION[User::SESSION_NAME] = 'visitor';
|
||||
return ["logged_in" => false, "is_visitor" => true];
|
||||
}
|
||||
|
||||
Log::put("login_fails", $nick);
|
||||
throw new Exception(__("The nick or password is incorrect."));
|
||||
}
|
||||
|
||||
public static function logout(){
|
||||
if(!Config::get_safe("force_login", false)){
|
||||
throw new Exception(__("You can't log out. There is no account."));
|
||||
}
|
||||
|
||||
if(!self::is_logged_in() && !self::is_visitor()){
|
||||
throw new Exception(__("You are not even logged in."));
|
||||
}
|
||||
|
||||
$_SESSION[User::SESSION_NAME] = false;
|
||||
return true;
|
||||
}
|
||||
}
|
33
common.php
|
@ -1,13 +1,38 @@
|
|||
<?php
|
||||
|
||||
// Define PROJECT PATH
|
||||
define('PROJECT_PATH', dirname(__FILE__));
|
||||
define('PROJECT_PATH', dirname(__FILE__).'/');
|
||||
define('APP_PATH', PROJECT_PATH.'app/');
|
||||
|
||||
// Load Autoloader
|
||||
require "lib/splclassloader.class.php";
|
||||
$classLoader = new SplClassLoader(null, PROJECT_PATH.'/lib');
|
||||
require APP_PATH."splclassloader.class.php";
|
||||
$classLoader = new SplClassLoader(null, APP_PATH);
|
||||
$classLoader->setFileExtension('.class.php');
|
||||
$classLoader->register();
|
||||
|
||||
// In debug mode, display errors
|
||||
if(Config::get_safe('debug', false)){
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
// Check extensions
|
||||
$required = ['curl', 'PDO', 'pdo_mysql', 'gd', 'exif'];
|
||||
$loaded = get_loaded_extensions();
|
||||
if($missing = array_diff($required, $loaded)){
|
||||
die("Missing extensions, please install: ".implode(", ", $missing));
|
||||
}
|
||||
}
|
||||
|
||||
// Language
|
||||
Lang::load(empty($_GET["hl"]) ? Config::get("lang") : $_GET["hl"]);
|
||||
|
||||
// Timezone
|
||||
if(false !== ($TZ = Config::get_safe('timezone', getenv('TZ')))) {
|
||||
date_default_timezone_set($TZ);
|
||||
ini_set('date.timezone', $TZ);
|
||||
}
|
||||
|
||||
// Start session
|
||||
session_start();
|
||||
ini_set('session.cookie_httponly', 1);
|
||||
session_start();
|
||||
|
|
71
config.ini
|
@ -1,24 +1,77 @@
|
|||
[database]
|
||||
;mysql_socket = /tmp/mariadb55.sock
|
||||
db_connection = sqlite
|
||||
;sqlite_db = data/sqlite.db
|
||||
|
||||
;[database]
|
||||
;db_connection = mysql
|
||||
;mysql_socket = /tmp/mysql.sock
|
||||
;mysql_host = localhost
|
||||
;mysql_port = 3306
|
||||
;mysql_user = root
|
||||
;mysql_pass =
|
||||
;db_name = root
|
||||
;mysql_pass = root
|
||||
;db_name = blog
|
||||
|
||||
;[database]
|
||||
;db_connection = postgres
|
||||
;postgres_socket = /tmp/postgres.sock
|
||||
;postgres_host = localhost
|
||||
;postgres_port = 5432
|
||||
;postgres_user = root
|
||||
;postgres_pass = root
|
||||
;db_name = blog
|
||||
|
||||
[profile]
|
||||
title = Blog
|
||||
name = Max Musermann
|
||||
pic_small = static/images/profile.jpg
|
||||
pic_big = static/images/profile_big.jpg
|
||||
cover = static/images/cover.jpg
|
||||
;cover = static/images/cover.jpg
|
||||
|
||||
[login]
|
||||
[language]
|
||||
lang = en
|
||||
|
||||
[components]
|
||||
highlight = true
|
||||
|
||||
[custom]
|
||||
theme = theme02
|
||||
;header = data/header.html
|
||||
;styles[] = static/styles/custom1.css
|
||||
;styles[] = static/styles/custom2.css
|
||||
;scripts = static/styles/scripts.css
|
||||
;footer = "Edit this if you really want to remove my backlink :("
|
||||
|
||||
[bbcode]
|
||||
;bbtags[quote] = "<quote>{param}</quote>"
|
||||
|
||||
[admin]
|
||||
force_login = true
|
||||
nick = demo
|
||||
pass = demo
|
||||
|
||||
[friends]
|
||||
;friends[user] = pass
|
||||
;friends[user] = pass
|
||||
|
||||
[directories]
|
||||
images_path = data/i/
|
||||
thumbnails_path = data/t/
|
||||
logs_path = data/logs/
|
||||
|
||||
[proxy]
|
||||
;proxy = hostname:port
|
||||
;proxyauth = username:password
|
||||
;proxytype = CURLPROXY_HTTP ; default, if not set
|
||||
;proxytype = CURLPROXY_SOCKS4
|
||||
;proxytype = CURLPROXY_SOCKS5
|
||||
|
||||
;URL_PREFIX type:
|
||||
;proxy = http://your.page.com/proxy.cgi?
|
||||
;proxyauth = username:password
|
||||
;proxytype = URL_PREFIX
|
||||
|
||||
[system]
|
||||
system_name = blog
|
||||
version = 1.01
|
||||
debug = true
|
||||
logs = false
|
||||
;timezone = Europe/Vienna
|
||||
version = 1.42
|
||||
debug = false
|
||||
logs = false
|
||||
|
|
17
docker-compose.yml
Normal file
|
@ -0,0 +1,17 @@
|
|||
version: "3"
|
||||
|
||||
services:
|
||||
blog:
|
||||
image: m1k1o/blog:latest
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
TZ: Europe/Vienna
|
||||
BLOG_TITLE: Blog
|
||||
BLOG_NAME: Max Musermann
|
||||
BLOG_NICK: username
|
||||
BLOG_PASS: password
|
||||
BLOG_LANG: en
|
||||
ports:
|
||||
- 80:80
|
||||
volumes:
|
||||
- ./data:/var/www/html/data
|
301
index.php
|
@ -3,103 +3,140 @@ include 'common.php';
|
|||
|
||||
// Create token
|
||||
if(empty($_SESSION['token'])){
|
||||
if(function_exists('mcrypt_create_iv')){
|
||||
$_SESSION['token'] = bin2hex(mcrypt_create_iv(5, MCRYPT_DEV_URANDOM));
|
||||
if(function_exists('random_bytes')){
|
||||
$_SESSION['token'] = bin2hex(random_bytes(5));
|
||||
} else {
|
||||
$_SESSION['token'] = bin2hex(openssl_random_pseudo_bytes(5));
|
||||
}
|
||||
}
|
||||
|
||||
function escape($str) {
|
||||
return htmlspecialchars($str, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
//$.ajaxSetup({headers:{'Csrf-Token':'token'}});
|
||||
|
||||
Log::put("visitors");
|
||||
|
||||
$year = intval(date("Y"));
|
||||
$years = '';
|
||||
for($y=$year-5;$y<=$year+5;$y++){
|
||||
$years .= sprintf('<option>%d</option>', $y);
|
||||
}
|
||||
|
||||
$months = '';
|
||||
for($m=1;$m<=12;$m++){
|
||||
$months .= sprintf('<option value="%d">%02d</option>', $m, $m);
|
||||
}
|
||||
|
||||
$days = '';
|
||||
for($d=1;$d<=31;$d++){
|
||||
$days .= sprintf('<option value="%d">%02d</option>', $d, $d);
|
||||
}
|
||||
|
||||
$hours = '';
|
||||
for($h=0;$h<=60;$h++){
|
||||
for($h=0;$h<24;$h++){
|
||||
$hours .= sprintf('<option value="%d">%02d</option>', $h, $h);
|
||||
}
|
||||
|
||||
$minutes = '';
|
||||
for($m=0;$m<=60;$m+=10){
|
||||
for($m=0;$m<60;$m+=10){
|
||||
$minutes .= sprintf('<option value="%d">%02d</option>', $m, $m);
|
||||
}
|
||||
|
||||
$header_path = PROJECT_PATH.Config::get_safe("header", 'data/header.html');
|
||||
if(file_exists($header_path)){
|
||||
$header = file_get_contents($header_path);
|
||||
} else {
|
||||
$header = '';
|
||||
}
|
||||
|
||||
// Translate styles into html
|
||||
$styles = Config::get_safe("styles", []);
|
||||
$styles_html = '';
|
||||
if(!empty($styles)){
|
||||
if(!is_array($styles)){
|
||||
$styles = [$styles];
|
||||
}
|
||||
|
||||
$styles = array_unique($styles);
|
||||
$styles = array_map('escape', $styles);
|
||||
$styles_html = '<link href="'.implode('" rel="stylesheet" type="text/css"/>'.PHP_EOL.'<link href="', $styles).'" rel="stylesheet" type="text/css"/>'.PHP_EOL;
|
||||
}
|
||||
|
||||
// Translate script urls into html
|
||||
$scripts = Config::get_safe("scripts", []);
|
||||
$scripts_html = '';
|
||||
if(!empty($scripts)){
|
||||
if(!is_array($scripts)){
|
||||
$scripts = [$scripts];
|
||||
}
|
||||
|
||||
$scripts = array_unique($scripts);
|
||||
$scripts = array_map('escape', $scripts);
|
||||
$scripts_html = '<script src="'.implode('" type="text/javascript"></script>'.PHP_EOL.'<script src="', $scripts).'" type="text/javascript"></script>'.PHP_EOL;
|
||||
}
|
||||
|
||||
// Use version suffix in URLs to prevent cache
|
||||
$versionSuffix = '';
|
||||
if (Config::get_safe("version", false)) {
|
||||
$versionSuffix = '?v='.rawurlencode(Config::get("version"));
|
||||
}
|
||||
|
||||
?><!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title><?php echo Config::get("title"); ?></title>
|
||||
<title><?php echo escape(Config::get("title")); ?></title>
|
||||
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
|
||||
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
||||
|
||||
<link href="static/styles/main.css?v=<?php echo Config::get("version"); ?>" rel="stylesheet" type="text/css" />
|
||||
<link href="static/styles/design.css?v=<?php echo Config::get("version"); ?>" rel="stylesheet" type="text/css" />
|
||||
|
||||
|
||||
<link href="static/styles/main.css<?php echo $versionSuffix?>" rel="stylesheet" type="text/css" />
|
||||
<link href="static/styles/<?php echo rawurlencode(Config::get_safe("theme", "theme01")); ?>.css<?php echo $versionSuffix?>" rel="stylesheet" type="text/css" />
|
||||
|
||||
<link href="https://fonts.googleapis.com/css?family=Open+Sans&subset=all" rel="stylesheet">
|
||||
|
||||
<link href="static/styles/lightbox.css" rel="stylesheet" type="text/css" />
|
||||
<?php echo Config::get_safe("highlight", false) ? '<link href="static/styles/highlight-monokai-sublime.css" rel="stylesheet" type="text/css" />'.PHP_EOL : ''; ?>
|
||||
|
||||
<?php echo $styles_html; ?>
|
||||
</head>
|
||||
<body>
|
||||
<div id="dd_mask" class="mask"></div>
|
||||
<div id="prepared" style="display:none;">
|
||||
<!-- Login Button -->
|
||||
<button type="button" class="button blue login_btn">Login</button>
|
||||
|
||||
<a class="show_more"><?php echo __("Show More"); ?></a>
|
||||
|
||||
<!-- Login Button -->
|
||||
<button type="button" class="button blue login_btn"><?php echo __("Login"); ?></button>
|
||||
|
||||
<!-- Logout Button -->
|
||||
<button type="button" class="button gray logout_btn">Logout</button>
|
||||
|
||||
<button type="button" class="button gray logout_btn"><?php echo __("Logout"); ?></button>
|
||||
|
||||
<!-- Login Modal -->
|
||||
<div class="modal login_modal">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-dialog" style="max-width: 350px;">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<a class="close"></a>
|
||||
<h4 class="modal-title">Login</h4>
|
||||
<h4 class="modal-title"><?php echo __("Login"); ?></h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<input type="text" class="nick" placeholder="Nick">
|
||||
<input type="password" class="pass" placeholder="Password">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a class="button gray close">Cancel</a>
|
||||
<button type="button" class="button blue do_login">Login</button>
|
||||
<form>
|
||||
<div class="modal-body login-form">
|
||||
<input name="username" type="text" autocomplete="username" class="nick" placeholder="<?php echo __("Nick"); ?>">
|
||||
<input name="password" type="password" autocomplete="current-password" class="pass" placeholder="<?php echo __("Password"); ?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a class="button gray close"><?php echo __("Cancel"); ?></a>
|
||||
<button type="button" class="button blue do_login"><?php echo __("Login"); ?></button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Post Link -->
|
||||
<a class="b_link" target="_blank">
|
||||
<div class="thumb">
|
||||
<img class="thumb_imglink">
|
||||
<div class="play"></div>
|
||||
</div>
|
||||
<div class="info right">
|
||||
<div class="info has_thumb">
|
||||
<div class="title"></div>
|
||||
<div class="desc"></div>
|
||||
<div class="host"></div>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
|
||||
<!-- Post Image Link -->
|
||||
<a class="b_imglink">
|
||||
<img>
|
||||
|
@ -109,47 +146,60 @@ for($m=0;$m<=60;$m+=10){
|
|||
<div class="desc"></div>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
|
||||
<!-- Post Image -->
|
||||
<a class="b_img"><img></a>
|
||||
|
||||
|
||||
<!-- New Post -->
|
||||
<div class="b_post new_post">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title">Post</h4>
|
||||
<h4 class="modal-title"><?php echo __("Post"); ?></h4>
|
||||
</div>
|
||||
<div class="edit-form"></div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Post Tools -->
|
||||
<ul class="b_dropdown post_tools">
|
||||
<li><a class="edit_post">Edit Post</a></li>
|
||||
<li><a class="edit_date">Change Date</a></li>
|
||||
<li><a class="hide">Hide from Timeline</a></li>
|
||||
<li><a class="delete_post">Delete</a></li>
|
||||
<li><a class="edit_post"><?php echo __("Edit Post"); ?></a></li>
|
||||
<li><a class="edit_date"><?php echo __("Change Date"); ?></a></li>
|
||||
<li>
|
||||
<a class="hide"><?php echo __("Hide from Timeline"); ?></a>
|
||||
<a class="show"><?php echo __("Show on Timeline"); ?></a>
|
||||
</li>
|
||||
<li><a class="delete_post"><?php echo __("Delete Post"); ?></a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
<!-- Edit Modal -->
|
||||
<div class="modal edit_modal">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<a class="close"></a>
|
||||
<h4 class="modal-title">Edit Post</h4>
|
||||
<h4 class="modal-title"><?php echo __("Edit Post"); ?></h4>
|
||||
</div>
|
||||
<div class="edit_form">
|
||||
<div class="modal-body drop_space">
|
||||
<div class="e_drag"><span>Drag photos here</span></div>
|
||||
<img src="<?php echo Config::get("pic_small"); ?>" width="40" height="40" class="e_profile">
|
||||
<div class="e_text" contenteditable="true" placeholder="What's on your mind?"></div>
|
||||
<div class="e_drag"><span><?php echo __("Drag photos here"); ?></span></div>
|
||||
<div class="e_drop"><span><?php echo __("Drop photos here"); ?></span></div>
|
||||
<img src="<?php echo escape(Config::get("pic_small")); ?>" width="40" height="40" class="e_profile">
|
||||
<!--<div class="e_text" contenteditable="true"></div>-->
|
||||
<div class="t_area">
|
||||
<textarea class="e_text" placeholder="<?php echo __("What's on your mind?"); ?>"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="e_loading">
|
||||
<span class="e_dots"></span>
|
||||
<span class="e_dots"></span>
|
||||
<span class="e_dots"></span>
|
||||
<div class="e_meter"><span></span></div>
|
||||
</div>
|
||||
<input type="hidden" class="i_content_type">
|
||||
<input type="hidden" class="i_content">
|
||||
<div class="modal-body content"></div>
|
||||
<table class="options_content">
|
||||
<tr class="feeling"><th>Feeling</th><td><input type="text" class="i_feeling" placeholder="How are you feeling?"><button class="clear"></button></td></tr>
|
||||
<tr class="persons"><th>With</th><td><input type="text" class="i_persons" placeholder="Who are you with?"><button class="clear"></button></td></tr>
|
||||
<tr class="location"><th>At</th><td><input type="text" class="i_location" placeholder="Where are you?"><button class="clear"></button></td></tr>
|
||||
<tr class="feeling"><th><?php echo __("Feeling"); ?></th><td><input type="text" class="i_feeling" placeholder="<?php echo __("How are you feeling?"); ?>" autocomplete="off"><button class="clear"></button></td></tr>
|
||||
<tr class="persons"><th><?php echo __("With"); ?></th><td><input type="text" class="i_persons" placeholder="<?php echo __("Who are you with?"); ?>" autocomplete="off"><button class="clear"></button></td></tr>
|
||||
<tr class="location"><th><?php echo __("At"); ?></th><td><input type="text" class="i_location" placeholder="<?php echo __("Where are you?"); ?>" autocomplete="off"><button class="clear"></button></td></tr>
|
||||
</table>
|
||||
<div class="modal-footer">
|
||||
<ul class="options">
|
||||
|
@ -159,83 +209,96 @@ for($m=0;$m<=60;$m+=10){
|
|||
<li class="location"><a></a></li>
|
||||
</ul>
|
||||
<div class="buttons">
|
||||
<span class="button gray pirvacy"><span class="cnt"></span><i class="arrow"></i></span>
|
||||
<button type="button" class="button blue save">Save</button>
|
||||
<span class="button gray privacy"><span class="cnt"></span><i class="arrow"></i></span>
|
||||
<button type="button" class="button blue save"><?php echo __("Save"); ?></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Edit Date Modal -->
|
||||
<div class="modal edit_date_modal">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-dialog small">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<a class="close"></a>
|
||||
<h4 class="modal-title">Change date</h4>
|
||||
<h4 class="modal-title"><?php echo __("Change Date"); ?></h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<select class="year">
|
||||
<option value="" disabled="1">Year:</option>
|
||||
<?php echo $years; ?>
|
||||
</select>
|
||||
<select class="month">
|
||||
<option value="" disabled="1">Month:</option>
|
||||
<?php echo $months; ?>
|
||||
</select>
|
||||
<select class="day">
|
||||
<option value="" disabled="1">Day:</option>
|
||||
<?php echo $days; ?>
|
||||
</select>
|
||||
<select class="hour">
|
||||
<option value="" disabled="1">Hour:</option>
|
||||
<?php echo $hours; ?>
|
||||
</select>
|
||||
<select class="minute">
|
||||
<option value="" disabled="1">Minute:</option>
|
||||
<?php echo $minutes; ?>
|
||||
</select>
|
||||
<div class="datepicker">
|
||||
<input type="hidden" class="year" value="">
|
||||
<input type="hidden" class="month" value="">
|
||||
<input type="hidden" class="day" value="">
|
||||
<input type="hidden" class="month_names" value="<?php echo
|
||||
__("January").",".
|
||||
__("February").",".
|
||||
__("March").",".
|
||||
__("April").",".
|
||||
__("May").",".
|
||||
__("June").",".
|
||||
__("July").",".
|
||||
__("August").",".
|
||||
__("September").",".
|
||||
__("October").",".
|
||||
__("November").",".
|
||||
__("December");
|
||||
?>">
|
||||
</div>
|
||||
<div style="text-align: center;">
|
||||
<?php echo __("Time:"); ?>
|
||||
<select class="hour">
|
||||
<option value="" disabled="1"><?php echo __("Hour:"); ?></option>
|
||||
<?php echo $hours; ?>
|
||||
</select> :
|
||||
<select class="minute">
|
||||
<option value="" disabled="1"><?php echo __("Minute:"); ?></option>
|
||||
<?php echo $minutes; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a class="button gray close">Cancel</a>
|
||||
<button type="button" class="button blue save">Save</button>
|
||||
<a class="button gray close"><?php echo __("Cancel"); ?></a>
|
||||
<button type="button" class="button blue save"><?php echo __("Save"); ?></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Delete Modal -->
|
||||
<div class="modal delete_modal">
|
||||
<div class="modal-dialog small">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<a class="close"></a>
|
||||
<h4 class="modal-title">Delete Post</h4>
|
||||
<h4 class="modal-title"><?php echo __("Delete Post"); ?></h4>
|
||||
</div>
|
||||
<div class="modal-body">This post will be deleted and you'll no longer be able to find it. You can also edit this post if you just want to change something.</div>
|
||||
<div class="modal-body"><?php echo __("This post will be deleted and you'll no longer be able to find it. You can also edit this post if you just want to change something."); ?></div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a class="button gray close">Cancel</a>
|
||||
<button type="button" class="button blue delete">Delete Post</button>
|
||||
<a class="button gray close"><?php echo __("Cancel"); ?></a>
|
||||
<button type="button" class="button blue delete"><?php echo __("Delete Post"); ?></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Post Row -->
|
||||
<div class="b_post post_row">
|
||||
<div class="b_overlay">
|
||||
<a class="button"><?php echo __("Show hidden content"); ?></a>
|
||||
</div>
|
||||
<div class="b_header">
|
||||
<img src="<?php echo Config::get("pic_small"); ?>" width="40" height="40" class="b_profile">
|
||||
<img src="<?php echo escape(Config::get("pic_small")); ?>" width="40" height="40" class="b_profile">
|
||||
<div class="b_desc">
|
||||
<div class="b_sharer">
|
||||
<span class="b_name"><?php echo Config::get("name"); ?></span><span class="b_options"> - </span><span class="b_feeling"></span><span class="b_with"> with </span><span class="b_persons"></span><span class="b_here"> here: </span><span class="b_location"></span>
|
||||
<span class="b_name"><?php echo escape(Config::get("name")); ?></span><span class="b_options"> - </span><span class="b_feeling"></span><span class="b_with"> <?php echo __("with"); ?> </span><span class="b_persons"></span><span class="b_here"> <?php echo __("here:"); ?> </span><span class="b_location"></span>
|
||||
</div>
|
||||
<i class="pirvacy_icon"></i>
|
||||
<i class="privacy_icon"></i>
|
||||
<a class="b_date"></a>
|
||||
<a class="b_tools"></a>
|
||||
</div>
|
||||
|
@ -243,46 +306,54 @@ for($m=0;$m<=60;$m+=10){
|
|||
<div class="b_text"></div>
|
||||
<div class="b_content"></div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Pirvacy Settings -->
|
||||
<ul class="b_dropdown pirvacy_settings">
|
||||
<li><a class="set" data-val="public"><i class="public"></i>Public</a></li>
|
||||
<!--<li><a class="set" data-val="friends"><i class="friends"></i>Friends</a></li>-->
|
||||
<li><a class="set" data-val="private"><i class="private"></i>Only me</a></li>
|
||||
<ul class="b_dropdown privacy_settings">
|
||||
<li><a class="set" data-val="public"><i class="public"></i><?php echo __("Public"); ?></a></li>
|
||||
<li><a class="set" data-val="friends"><i class="friends"></i><?php echo __("Friends"); ?></a></li>
|
||||
<li><a class="set" data-val="private"><i class="private"></i><?php echo __("Only me"); ?></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="bluebar">
|
||||
<h1><?php echo Config::get("title"); ?></h1>
|
||||
<h1><?php echo escape(Config::get("title")); ?></h1>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="headbar">
|
||||
<div class="cover">
|
||||
<?php echo $header; ?>
|
||||
<div class="overlay"></div>
|
||||
<img src="<?php echo Config::get("cover"); ?>">
|
||||
<?php echo (Config::get_safe("cover", false) ? '<img src="'.escape(Config::get("cover")).'">' : (empty($header) ? '<div style="padding-bottom: 37%;"></div>' : '')); ?>
|
||||
<div class="profile">
|
||||
<img src="<?php echo Config::get("pic_big"); ?>">
|
||||
<img src="<?php echo escape(Config::get("pic_big")); ?>">
|
||||
</div>
|
||||
<div class="name"><?php echo Config::get("name"); ?></div>
|
||||
<div class="name"><?php echo escape(Config::get("name")); ?></div>
|
||||
</div>
|
||||
<div id="headline"></div>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="b_feed">
|
||||
<div class="more_posts">
|
||||
<a href="#" class="button">Show all posts</a>
|
||||
<a href="#" class="button"><?php echo __("Show all posts"); ?></a>
|
||||
</div>
|
||||
<div id="posts"></div>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="eof_feed">
|
||||
<img src="static/images/zpEYXu5Wdu6.png">
|
||||
<p><?php echo Config::get("version"); ?> © 2016 <br>Miroslav Šedivý</p>
|
||||
<p><?php echo escape(Config::get("version")); ?> © 2016-2022<br>
|
||||
<?php echo Config::get_safe("footer", false) ? escape(Config::get_safe("footer")) : '<a href="https://github.com/m1k1o/blog" class="link" title="m1k1o/blog github repository" target="_blank">m1k1o/blog</a>'; ?>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
|
||||
<!--<script src="static/scripts/jquery.min.js"></script>-->
|
||||
<script src="static/scripts/jquery.min.js"></script>
|
||||
<script>$["\x61\x6A\x61\x78\x53\x65\x74\x75\x70"]({"\x68\x65\x61\x64\x65\x72\x73":{"\x43\x73\x72\x66-\x54\x6F\x6B\x65\x6E":"<?php echo $_SESSION['token'];?>"}});</script>
|
||||
<script src="static/scripts/app.js?v=<?php echo Config::get("version"); ?>"></script>
|
||||
|
||||
<script src="static/scripts/lightbox.js"></script>
|
||||
<script src="static/scripts/datepick.js<?php echo $versionSuffix?>"></script>
|
||||
<script src="static/scripts/autosize.js"></script>
|
||||
<?php echo Config::get_safe("highlight", false) ? '<script src="static/scripts/highlight-10.1.2.min.js"></script><script>hljs.initHighlightingOnLoad();</script>'.PHP_EOL : ''; ?>
|
||||
<script src="static/scripts/app.js<?php echo $versionSuffix?>"></script>
|
||||
|
||||
<?php echo $scripts_html; ?>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
<?php
|
||||
|
||||
class Config
|
||||
{
|
||||
private static $_settings = [];
|
||||
|
||||
private static function init(){
|
||||
$config_file = PROJECT_PATH.'/config.ini';
|
||||
|
||||
if(!is_readable($config_file)){
|
||||
throw new ConfigException('Cannot read config file');
|
||||
}
|
||||
|
||||
self::$_settings = parse_ini_file($config_file);
|
||||
$custom_config = PROJECT_PATH.'/custom.ini';
|
||||
|
||||
if(is_readable($custom_config)){
|
||||
$custom = parse_ini_file(PROJECT_PATH.'/custom.ini');
|
||||
if($custom !== false){
|
||||
self::$_settings = array_merge(self::$_settings, $custom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function get($key){
|
||||
if(empty(self::$_settings)){
|
||||
self::init();
|
||||
}
|
||||
|
||||
if(!array_key_exists($key, self::$_settings)){
|
||||
throw new ConfigException('Key "'.$key.'" not found in settings');
|
||||
}
|
||||
|
||||
return self::$_settings[$key];
|
||||
}
|
||||
|
||||
public static function get_safe($key, $default = ''){
|
||||
try {
|
||||
$value = self::get($key);
|
||||
} catch (ConfigException $e) {
|
||||
$value = $default;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
class ConfigException extends Exception{}
|
|
@ -1,135 +0,0 @@
|
|||
<?php
|
||||
|
||||
class Image
|
||||
{
|
||||
const CHMOD = 775;
|
||||
|
||||
private static function random_str($len = 10){
|
||||
$chr = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
||||
$chr_len = strlen($chr);
|
||||
$random_str = '';
|
||||
|
||||
for($i = 0; $i < $len; $i++){
|
||||
$random_str .= $chr[rand(0, $chr_len - 1)];
|
||||
}
|
||||
|
||||
return $random_str;
|
||||
}
|
||||
|
||||
private static function thumb($source_path, $thumb_path){
|
||||
ini_set('memory_limit', '128M');
|
||||
|
||||
$thumb_w = 476;
|
||||
$thumb_h = 476;
|
||||
|
||||
$source_details = getimagesize($source_path);
|
||||
$source_w = $source_details[0];
|
||||
$source_h = $source_details[1];
|
||||
|
||||
if($source_w > $source_h){
|
||||
$new_w = $thumb_w;
|
||||
$new_h = intval($source_h * $new_w / $source_w);
|
||||
} else {
|
||||
$new_h = $thumb_h;
|
||||
$new_w = intval($source_w * $new_h / $source_h);
|
||||
}
|
||||
|
||||
switch($source_details[2]){
|
||||
case IMAGETYPE_GIF:
|
||||
$imgt = "ImageGIF";
|
||||
$imgcreatefrom = "ImageCreateFromGIF";
|
||||
break;
|
||||
|
||||
case IMAGETYPE_JPEG:
|
||||
$imgt = "ImageJPEG";
|
||||
$imgcreatefrom = "ImageCreateFromJPEG";
|
||||
break;
|
||||
|
||||
case IMAGETYPE_PNG:
|
||||
$imgt = "ImagePNG";
|
||||
$imgcreatefrom = "ImageCreateFromPNG";
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
$old_image = $imgcreatefrom($source_path);
|
||||
$new_image = imagecreatetruecolor($new_w, $new_h);
|
||||
imagecopyresampled($new_image, $old_image, 0, 0, 0, 0, $new_w, $new_h, $source_w, $source_h);
|
||||
//$new_image = imagecreatetruecolor($thumb_w, $thumb_h);
|
||||
//imagecopyresized($new_image, $old_image, $dest_x, $dest_y, 0, 0, $new_w, $new_h, $source_w, $source_h);
|
||||
return $imgt($new_image, $thumb_path);
|
||||
}
|
||||
|
||||
public static function upload($name, $data){
|
||||
$photo = null;
|
||||
$ext = null;
|
||||
|
||||
if($data){
|
||||
preg_match('/^data\:image\/(jpe?g|png|gif)\;base64,(.*)$/', $data, $m);
|
||||
|
||||
if(!$m){
|
||||
throw new Excrption("Invalid file.");
|
||||
}
|
||||
|
||||
$ext = $m[1];
|
||||
if($ext == "jpeg") $ext = "jpg";
|
||||
|
||||
// Decode photo
|
||||
$photo = base64_decode($m[2]);
|
||||
}
|
||||
|
||||
if($_FILES){
|
||||
$photo = file_get_contents($_FILES["file"]["tmp_name"]);
|
||||
$name = $_FILES['file']['name'];
|
||||
$ext = pathinfo($name, PATHINFO_EXTENSION);
|
||||
}
|
||||
|
||||
if(!$_FILES && !$data){
|
||||
throw new Excrption("No file.");
|
||||
}
|
||||
|
||||
// Create MD5
|
||||
$md5 = md5($photo);
|
||||
|
||||
// Find duplicate
|
||||
if($d = DB::get_instance()->query("SELECT `path`, `thumb` FROM `images` WHERE `md5` = ? AND `status` = 1 LIMIT 1", $md5)->first()){
|
||||
return $d;
|
||||
}
|
||||
|
||||
// Save to DB
|
||||
$id = DB::get_instance()->query(
|
||||
"INSERT INTO `images` ".
|
||||
"(`id`, `name`, `path`, `thumb`, `type`, `md5`, `datetime`, `status`) ".
|
||||
"VALUES (NULL, ?, NULL, NULL, ?, ?, NOW(), 1);",
|
||||
$name, $ext, $md5
|
||||
)->last_id();
|
||||
|
||||
// Create path name
|
||||
$name = dechex($id).self::random_str(3).".".$ext;
|
||||
$path = 'i/'.$name;
|
||||
$thumb = 't/'.$name;
|
||||
|
||||
// Save path
|
||||
if(false === file_put_contents($path, $photo)){
|
||||
// Try to set chmod
|
||||
if(chmod("i", Image::CHMOD) && chmod("t", Image::CHMOD)){
|
||||
throw new Exception("Can't write to file. Chmod has been changed, try again.");
|
||||
}
|
||||
|
||||
DB::get_instance()->query("UPDATE `images` SET `status` = 0 WHERE `id` = ?", $id);
|
||||
throw new Exception("Can't write to file.");
|
||||
}
|
||||
|
||||
// Create thumb
|
||||
self::thumb($path, $thumb);
|
||||
|
||||
// Save to DB
|
||||
DB::get_instance()->query("UPDATE `images` SET `path` = ?, `thumb` = ?, `status` = ? WHERE `id` = ?", $path, $thumb, $status, $id);
|
||||
return [
|
||||
"path" => $path,
|
||||
"thumb" => $thumb
|
||||
];
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
|
||||
class Log
|
||||
{
|
||||
private static $_files = [
|
||||
"ajax_access",
|
||||
"ajax_errors",
|
||||
"login_fails",
|
||||
"visitors"
|
||||
];
|
||||
|
||||
private static $_path = 'logs/';
|
||||
|
||||
public static function put($_file, $_text = null){
|
||||
if(!Config::get_safe("logs", false) || !in_array($_file, static::$_files)){
|
||||
return ;
|
||||
}
|
||||
|
||||
if(false === file_put_contents(PROJECT_PATH.DIRECTORY_SEPARATOR.static::$_path.$_file.".log", self::line($_text), FILE_APPEND)){
|
||||
trigger_error("Can't write to {$_file}.log file.", E_USER_NOTICE);
|
||||
}
|
||||
}
|
||||
|
||||
private static function line($_text = null){
|
||||
return date('Y-m-d H:i:s')."\t".$_SERVER["REMOTE_ADDR"]."\t".$_SERVER["HTTP_USER_AGENT"].($_text ? "\t".$_text : "").PHP_EOL;
|
||||
}
|
||||
}
|
|
@ -1,253 +0,0 @@
|
|||
<?php
|
||||
|
||||
class Post
|
||||
{
|
||||
private static function login_protected(){
|
||||
if(!User::is_logged_in()){
|
||||
throw new Exception("You need to be logged in to perform this action.");
|
||||
}
|
||||
}
|
||||
|
||||
private static function pirvacy($c){
|
||||
if($c == "public" || $c == "friends"){
|
||||
return $c;
|
||||
}
|
||||
|
||||
return "private";
|
||||
}
|
||||
|
||||
private static function parse_content($c){
|
||||
//$c = htmlentities($c);
|
||||
|
||||
// Links
|
||||
$c = preg_replace('/\"([^\"]+)\"/i', "„$1\"", $c);
|
||||
|
||||
$c = preg_replace('/(https?\:\/\/[^\" \n]+)/i', "<a href=\"\\0\" target=\"_blank\">\\0</a>", $c);
|
||||
$c = preg_replace('/(\#[A-Za-z0-9-_]+)/i', "<span class=\"tag\">\\0</span>", $c);
|
||||
|
||||
////Headlines
|
||||
//$c = preg_replace('/^\# (.*)$/m', "<h1>$1</h1>", $c);
|
||||
//$c = preg_replace('/^\#\# (.*)$/m', "<h2>$1</h2>", $c);
|
||||
//$c = preg_replace('/^\#\#\# (.*)$/m', "<h3>$1</h3>", $c);
|
||||
|
||||
//$c = preg_replace('/\"([^\"]+)\"/i', "„ <i>$1</i> “", $c);
|
||||
$c = preg_replace('/\*([^\*]+)\*/i', "<strong>$1</strong>", $c);
|
||||
|
||||
$c = nl2br($c);
|
||||
|
||||
return $c;
|
||||
}
|
||||
|
||||
private static function get_title($url){
|
||||
$str = file_get_contents($url);
|
||||
if(strlen($str)>0){
|
||||
$str = trim(preg_replace('/\s+/', ' ', $str)); // supports line breaks inside <title>
|
||||
preg_match("/\<title\>(.*)\<\/title\>/i",$str,$title); // ignore case
|
||||
return $title[1];
|
||||
}
|
||||
}
|
||||
|
||||
public static function insert($r){
|
||||
self::login_protected();
|
||||
|
||||
$p = self::pirvacy($r["pirvacy"]);
|
||||
$text = self::parse_content($r["text"]);
|
||||
$post_id = DB::get_instance()->query(
|
||||
"INSERT INTO `posts` ".
|
||||
"(`id`, `text`, `plain_text`, `feeling`, `persons`, `location`, `pirvacy`, `content_type`, `content`, `datetime`, `status`) ".
|
||||
"VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), 1);",
|
||||
$text, $r["text"], $r["feeling"], $r["persons"], $r["location"], $p, $r["content_type"], $r["content"]
|
||||
)->last_id();
|
||||
|
||||
return [
|
||||
"text" => $text,
|
||||
"feeling" => $r["feeling"],
|
||||
"persons" => $r["persons"],
|
||||
"location" => $r["location"],
|
||||
"pirvacy" => $p,
|
||||
"content_type" => $r["content_type"],
|
||||
"content" => $r["content"],
|
||||
"datetime" => date("d M Y H:i"),
|
||||
"id" => $post_id
|
||||
];
|
||||
}
|
||||
|
||||
public static function update($r){
|
||||
self::login_protected();
|
||||
|
||||
$r["pirvacy"] = self::pirvacy($r["pirvacy"]);
|
||||
$plain_text = $r["text"];
|
||||
$r["text"] = self::parse_content($r["text"]);
|
||||
DB::get_instance()->query("UPDATE `posts` SET `text` = ?, `plain_text` = ?, `feeling` = ?, `persons` = ?, `location` = ?, `pirvacy` = ?, `content_type` = ?, `content` = ? WHERE `id` = ? AND `status` = 1", $r["text"], $plain_text, $r["feeling"], $r["persons"], $r["location"], $r["pirvacy"], $r["content_type"], $r["content"], $r["id"]);
|
||||
return $r;
|
||||
}
|
||||
|
||||
public static function hide($r){
|
||||
self::login_protected();
|
||||
|
||||
DB::get_instance()->query("UPDATE `posts` SET `status` = 4 WHERE `id` = ?", $r["id"]);
|
||||
return ["done" => true];
|
||||
}
|
||||
|
||||
public static function delete($r){
|
||||
self::login_protected();
|
||||
|
||||
DB::get_instance()->query("UPDATE `posts` SET `status` = 5 WHERE `id` = ?", $r["id"]);
|
||||
return ["done" => true];
|
||||
}
|
||||
|
||||
public static function edit_data($r){
|
||||
self::login_protected();
|
||||
|
||||
return DB::get_instance()->query("SELECT `plain_text` AS `text`, `feeling`, `persons`, `location`, `pirvacy`, `content_type`, `content` FROM `posts` WHERE `id` = ? AND `status` = 1", $r["id"])->first();
|
||||
}
|
||||
|
||||
public static function get_date($r){
|
||||
self::login_protected();
|
||||
|
||||
$date = DB::get_instance()->query("SELECT DATE_FORMAT(`datetime`,'%Y %c %e %k %i') AS `date_format` FROM `posts` WHERE `id` = ? AND `status` = 1", $r["id"])->first("date_format");
|
||||
$date = array_map("intval", explode(" ", $date));
|
||||
$date[4] = floor($date[4]/10)*10;
|
||||
return $date;
|
||||
}
|
||||
|
||||
public static function set_date($r){
|
||||
self::login_protected();
|
||||
|
||||
$d = $r["date"];
|
||||
$datetime = "{$d[0]}/{$d[1]}/{$d[2]} {$d[3]}:{$d[4]}";
|
||||
DB::get_instance()->query("UPDATE `posts` SET `datetime` = ? WHERE `id` = ? AND `status` = 1", $datetime, $r["id"]);
|
||||
return [
|
||||
"datetime" => date("d M Y H:i", strtotime($datetime))
|
||||
];
|
||||
}
|
||||
|
||||
public static function parse_link($r){
|
||||
self::login_protected();
|
||||
|
||||
$l = $r["link"];
|
||||
|
||||
preg_match('/^https?:\/\/([^:\/\s]+)([^\/\s]*\/)([^\.\s]+)\.(jpe?g|png|gif)((\?|\#)(.*))?$/i', $l, $img);
|
||||
if($img){
|
||||
return [
|
||||
"valid" => true,
|
||||
"content_type" => "img_link",
|
||||
"content" => [
|
||||
"src" => $l,
|
||||
"host" => $img[1]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
preg_match('/^https?:\/\/(www\.)?([^:\/\s]+)(.*)?$/i', $l, $url);
|
||||
|
||||
// Get content
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_URL, $l);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Proxycat/1.1)");
|
||||
curl_setopt($ch, CURLOPT_REFERER, '');
|
||||
$html = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
// Parse
|
||||
$doc = new DOMDocument();
|
||||
@$doc->loadHTML('<?xml encoding="utf-8" ?>'.$html);
|
||||
|
||||
// Get title
|
||||
$nodes = $doc->getElementsByTagName('title');
|
||||
$title = $nodes->item(0)->nodeValue;
|
||||
|
||||
// Content
|
||||
$content = [
|
||||
"link" => $l,
|
||||
"title" => ($title ? $title : $url[2]),
|
||||
"is_video" => false,
|
||||
"host" => $url[2]
|
||||
];
|
||||
|
||||
// Metas
|
||||
$metas = $doc->getElementsByTagName('meta');
|
||||
for($i = 0; $i < $metas->length; $i++){
|
||||
$meta = $metas->item($i);
|
||||
|
||||
$n = $meta->getAttribute('name');
|
||||
$p = $meta->getAttribute('property');
|
||||
$c = $meta->getAttribute('content');
|
||||
|
||||
if($n == 'twitter:description' || $p == 'og:description' || $n == 'description'){
|
||||
$content["desc"] = substr($c, 0, 180);
|
||||
}
|
||||
|
||||
if($n == 'twitter:title' || $p == 'og:title' || $p == 'title'){
|
||||
$content["title"] = $c;
|
||||
}
|
||||
|
||||
if($p == 'og:url'){
|
||||
$content["link"] = $c;
|
||||
}
|
||||
|
||||
if($p == 'og:type'){
|
||||
$content["is_video"] = ($c == "video");
|
||||
}
|
||||
|
||||
if($n == 'twitter:image:src' || $p == 'og:image'){
|
||||
$content["thumb"] = $c;
|
||||
}
|
||||
|
||||
if($n == 'twitter:domain'){
|
||||
$content["host"] = $c;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
"valid" => true,
|
||||
"content_type" => "link",
|
||||
"content" => $content
|
||||
];
|
||||
}
|
||||
|
||||
public static function upload_image($r){
|
||||
self::login_protected();
|
||||
|
||||
return Image::upload($r["name"], $r["data"]);
|
||||
}
|
||||
|
||||
public static function load($r){
|
||||
$until = null;
|
||||
if(preg_match("/^([0-9]{4})-([0-9]{2})$/", $r["filter"]["until"])){
|
||||
$until = $r["filter"]["until"]."-01 00:00";
|
||||
}
|
||||
|
||||
$id = null;
|
||||
if($r["filter"]["id"]){
|
||||
$id = intval($r["filter"]["id"]);
|
||||
}
|
||||
|
||||
return DB::get_instance()->query(
|
||||
"SELECT `id`, `text`, `feeling`, `persons`, `location`, `pirvacy`, `content_type`, `content`, DATE_FORMAT(`posts`.`datetime`,'%d %b %Y %H:%i') AS `datetime` ".
|
||||
"FROM `posts` ".
|
||||
"WHERE ".
|
||||
(!User::is_logged_in() ? "`pirvacy` = 'public' AND " : "").
|
||||
($until ? "`posts`.`datetime` < DATE_ADD('{$until}', INTERVAL +1 MONTH) AND " : "").
|
||||
($id ? "`id` = {$id} AND " : "").
|
||||
"`status` = 1 ".
|
||||
"ORDER BY `posts`.`datetime` DESC ".
|
||||
"LIMIT ? OFFSET ?", $r["limit"], $r["offset"]
|
||||
)->all();
|
||||
}
|
||||
|
||||
public static function login($r){
|
||||
return User::login($r["nick"], $r["pass"]);
|
||||
}
|
||||
|
||||
public static function logout(){
|
||||
return User::logout();
|
||||
}
|
||||
|
||||
public static function handshake($r){
|
||||
return ["logged_in" => User::is_logged_in()];
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
<?php
|
||||
|
||||
class user
|
||||
{
|
||||
const SESSION_NAME = "logged_in";
|
||||
|
||||
public static function is_logged_in(){
|
||||
if(!Config::get_safe("force_login", false)){
|
||||
return true;
|
||||
}
|
||||
|
||||
return !empty($_SESSION[User::SESSION_NAME]) && $_SESSION[User::SESSION_NAME] == md5(Config::get("nick").Config::get_safe("pass", ""));
|
||||
}
|
||||
|
||||
public static function login($nick, $pass){
|
||||
if(!Config::get_safe("force_login", false)){
|
||||
return true;
|
||||
}
|
||||
|
||||
if(self::is_logged_in()){
|
||||
throw new Exception("You are already logged in.");
|
||||
}
|
||||
|
||||
if(Config::get("nick") == $nick && Config::get_safe("pass", "") == $pass){
|
||||
$_SESSION[User::SESSION_NAME] = md5($nick.$pass);
|
||||
return true;
|
||||
}
|
||||
|
||||
Log::put("login_fails", $nick);
|
||||
throw new Exception("The nick or password is incorrect.");
|
||||
}
|
||||
|
||||
public static function logout(){
|
||||
if(!Config::get_safe("force_login", false)){
|
||||
throw new Exception("You can't log out. There is no account.");
|
||||
}
|
||||
|
||||
if(!self::is_logged_in()){
|
||||
throw new Exception("You are not even logged in.");
|
||||
}
|
||||
|
||||
$_SESSION[User::SESSION_NAME] = false;
|
||||
return true;
|
||||
}
|
||||
}
|
BIN
static/images/close.png
Normal file
After Width: | Height: | Size: 280 B |
BIN
static/images/loading.gif
Normal file
After Width: | Height: | Size: 8.3 KiB |
BIN
static/images/next.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
static/images/prev.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
static/images/star.png
Normal file
After Width: | Height: | Size: 470 B |
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 6.5 KiB |
Before Width: | Height: | Size: 238 B After Width: | Height: | Size: 238 B |
Before Width: | Height: | Size: 234 B After Width: | Height: | Size: 234 B |
Before Width: | Height: | Size: 238 B After Width: | Height: | Size: 238 B |
Before Width: | Height: | Size: 201 B After Width: | Height: | Size: 201 B |
Before Width: | Height: | Size: 234 B After Width: | Height: | Size: 234 B |
Before Width: | Height: | Size: 9.9 KiB After Width: | Height: | Size: 9.9 KiB |
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 4.8 KiB |
Before Width: | Height: | Size: 201 B After Width: | Height: | Size: 201 B |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
BIN
static/images/theme02/2CGkY1_Ax_-.png
Normal file
After Width: | Height: | Size: 593 B |
BIN
static/images/theme02/38mmIT7r0jG.png
Normal file
After Width: | Height: | Size: 835 B |
BIN
static/images/theme02/7_Yye-V3r9M.png
Normal file
After Width: | Height: | Size: 605 B |
BIN
static/images/theme02/7wYk0RRj5-g.png
Normal file
After Width: | Height: | Size: 511 B |
BIN
static/images/theme02/BOCzaD2rwOa.png
Normal file
After Width: | Height: | Size: 292 B |
BIN
static/images/theme02/BvwOjzIAV9T.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
static/images/theme02/HxCo9uaZIcB.png
Normal file
After Width: | Height: | Size: 330 B |
BIN
static/images/theme02/IBOXrWGhcIu.png
Normal file
After Width: | Height: | Size: 334 B |
BIN
static/images/theme02/LiJKvoYFmUK.png
Normal file
After Width: | Height: | Size: 513 B |
BIN
static/images/theme02/THYN1-y3aPS.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
static/images/theme02/W5IvJHzSLg7.png
Normal file
After Width: | Height: | Size: 927 B |
BIN
static/images/theme02/Xe-tUjaQ4vo.png
Normal file
After Width: | Height: | Size: 1 KiB |
BIN
static/images/theme02/YFO-fzIJZ2K.png
Normal file
After Width: | Height: | Size: 628 B |
BIN
static/images/theme02/amepTQ7nV0z.png
Normal file
After Width: | Height: | Size: 418 B |
BIN
static/images/theme02/gc6VwTsu2qZ.png
Normal file
After Width: | Height: | Size: 686 B |
BIN
static/images/theme02/jcKElmriUSj.png
Normal file
After Width: | Height: | Size: 367 B |
BIN
static/images/theme02/kOtcUC5Tvlq.png
Normal file
After Width: | Height: | Size: 509 B |
BIN
static/images/theme02/mHY-L01FIF0.png
Normal file
After Width: | Height: | Size: 601 B |
BIN
static/images/theme02/qZPl7lx7zY1.png
Normal file
After Width: | Height: | Size: 833 B |
BIN
static/images/theme02/xGM66u5seRO.png
Normal file
After Width: | Height: | Size: 887 B |
BIN
static/images/trophy.png
Normal file
After Width: | Height: | Size: 489 B |
BIN
static/screenshot-theme01.png
Normal file
After Width: | Height: | Size: 935 KiB |
BIN
static/screenshot-theme02-dark.png
Normal file
After Width: | Height: | Size: 1.1 MiB |
BIN
static/screenshot-theme02-light.png
Normal file
After Width: | Height: | Size: 1.1 MiB |
292
static/scripts/autosize.js
Normal file
|
@ -0,0 +1,292 @@
|
|||
/*!
|
||||
Autosize 4.0.0
|
||||
license: MIT
|
||||
http://www.jacklmoore.com/autosize
|
||||
*/
|
||||
(function (global, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define(['exports', 'module'], factory);
|
||||
} else if (typeof exports !== 'undefined' && typeof module !== 'undefined') {
|
||||
factory(exports, module);
|
||||
} else {
|
||||
var mod = {
|
||||
exports: {}
|
||||
};
|
||||
factory(mod.exports, mod);
|
||||
global.autosize = mod.exports;
|
||||
}
|
||||
})(this, function (exports, module) {
|
||||
'use strict';
|
||||
|
||||
var map = typeof Map === "function" ? new Map() : (function () {
|
||||
var keys = [];
|
||||
var values = [];
|
||||
|
||||
return {
|
||||
has: function has(key) {
|
||||
return keys.indexOf(key) > -1;
|
||||
},
|
||||
get: function get(key) {
|
||||
return values[keys.indexOf(key)];
|
||||
},
|
||||
set: function set(key, value) {
|
||||
if (keys.indexOf(key) === -1) {
|
||||
keys.push(key);
|
||||
values.push(value);
|
||||
}
|
||||
},
|
||||
'delete': function _delete(key) {
|
||||
var index = keys.indexOf(key);
|
||||
if (index > -1) {
|
||||
keys.splice(index, 1);
|
||||
values.splice(index, 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
var createEvent = function createEvent(name) {
|
||||
return new Event(name, { bubbles: true });
|
||||
};
|
||||
try {
|
||||
new Event('test');
|
||||
} catch (e) {
|
||||
// IE does not support `new Event()`
|
||||
createEvent = function (name) {
|
||||
var evt = document.createEvent('Event');
|
||||
evt.initEvent(name, true, false);
|
||||
return evt;
|
||||
};
|
||||
}
|
||||
|
||||
function assign(ta) {
|
||||
if (!ta || !ta.nodeName || ta.nodeName !== 'TEXTAREA' || map.has(ta)) return;
|
||||
|
||||
var heightOffset = null;
|
||||
var clientWidth = ta.clientWidth;
|
||||
var cachedHeight = null;
|
||||
|
||||
function init() {
|
||||
var style = window.getComputedStyle(ta, null);
|
||||
|
||||
if (style.resize === 'vertical') {
|
||||
ta.style.resize = 'none';
|
||||
} else if (style.resize === 'both') {
|
||||
ta.style.resize = 'horizontal';
|
||||
}
|
||||
|
||||
if (style.boxSizing === 'content-box') {
|
||||
heightOffset = -(parseFloat(style.paddingTop) + parseFloat(style.paddingBottom));
|
||||
} else {
|
||||
heightOffset = parseFloat(style.borderTopWidth) + parseFloat(style.borderBottomWidth);
|
||||
}
|
||||
// Fix when a textarea is not on document body and heightOffset is Not a Number
|
||||
if (isNaN(heightOffset)) {
|
||||
heightOffset = 0;
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
function changeOverflow(value) {
|
||||
{
|
||||
// Chrome/Safari-specific fix:
|
||||
// When the textarea y-overflow is hidden, Chrome/Safari do not reflow the text to account for the space
|
||||
// made available by removing the scrollbar. The following forces the necessary text reflow.
|
||||
var width = ta.style.width;
|
||||
ta.style.width = '0px';
|
||||
// Force reflow:
|
||||
/* jshint ignore:start */
|
||||
ta.offsetWidth;
|
||||
/* jshint ignore:end */
|
||||
ta.style.width = width;
|
||||
}
|
||||
|
||||
ta.style.overflowY = value;
|
||||
}
|
||||
|
||||
function getParentOverflows(el) {
|
||||
var arr = [];
|
||||
|
||||
while (el && el.parentNode && el.parentNode instanceof Element) {
|
||||
if (el.parentNode.scrollTop) {
|
||||
arr.push({
|
||||
node: el.parentNode,
|
||||
scrollTop: el.parentNode.scrollTop
|
||||
});
|
||||
}
|
||||
el = el.parentNode;
|
||||
}
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
function resize() {
|
||||
var originalHeight = ta.style.height;
|
||||
var overflows = getParentOverflows(ta);
|
||||
var docTop = document.documentElement && document.documentElement.scrollTop; // Needed for Mobile IE (ticket #240)
|
||||
|
||||
ta.style.height = '';
|
||||
|
||||
var endHeight = ta.scrollHeight + heightOffset;
|
||||
|
||||
if (ta.scrollHeight === 0) {
|
||||
// If the scrollHeight is 0, then the element probably has display:none or is detached from the DOM.
|
||||
ta.style.height = originalHeight;
|
||||
return;
|
||||
}
|
||||
|
||||
ta.style.height = endHeight + 'px';
|
||||
|
||||
// used to check if an update is actually necessary on window.resize
|
||||
clientWidth = ta.clientWidth;
|
||||
|
||||
// prevents scroll-position jumping
|
||||
overflows.forEach(function (el) {
|
||||
el.node.scrollTop = el.scrollTop;
|
||||
});
|
||||
|
||||
if (docTop) {
|
||||
document.documentElement.scrollTop = docTop;
|
||||
}
|
||||
}
|
||||
|
||||
function update() {
|
||||
resize();
|
||||
|
||||
var styleHeight = Math.round(parseFloat(ta.style.height));
|
||||
var computed = window.getComputedStyle(ta, null);
|
||||
|
||||
// Using offsetHeight as a replacement for computed.height in IE, because IE does not account use of border-box
|
||||
var actualHeight = computed.boxSizing === 'content-box' ? Math.round(parseFloat(computed.height)) : ta.offsetHeight;
|
||||
|
||||
// The actual height not matching the style height (set via the resize method) indicates that
|
||||
// the max-height has been exceeded, in which case the overflow should be allowed.
|
||||
if (actualHeight !== styleHeight) {
|
||||
if (computed.overflowY === 'hidden') {
|
||||
changeOverflow('scroll');
|
||||
resize();
|
||||
actualHeight = computed.boxSizing === 'content-box' ? Math.round(parseFloat(window.getComputedStyle(ta, null).height)) : ta.offsetHeight;
|
||||
}
|
||||
} else {
|
||||
// Normally keep overflow set to hidden, to avoid flash of scrollbar as the textarea expands.
|
||||
if (computed.overflowY !== 'hidden') {
|
||||
changeOverflow('hidden');
|
||||
resize();
|
||||
actualHeight = computed.boxSizing === 'content-box' ? Math.round(parseFloat(window.getComputedStyle(ta, null).height)) : ta.offsetHeight;
|
||||
}
|
||||
}
|
||||
|
||||
if (cachedHeight !== actualHeight) {
|
||||
cachedHeight = actualHeight;
|
||||
var evt = createEvent('autosize:resized');
|
||||
try {
|
||||
ta.dispatchEvent(evt);
|
||||
} catch (err) {
|
||||
// Firefox will throw an error on dispatchEvent for a detached element
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=889376
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var pageResize = function pageResize() {
|
||||
if (ta.clientWidth !== clientWidth) {
|
||||
update();
|
||||
}
|
||||
};
|
||||
|
||||
var destroy = (function (style) {
|
||||
window.removeEventListener('resize', pageResize, false);
|
||||
ta.removeEventListener('input', update, false);
|
||||
ta.removeEventListener('keyup', update, false);
|
||||
ta.removeEventListener('autosize:destroy', destroy, false);
|
||||
ta.removeEventListener('autosize:update', update, false);
|
||||
|
||||
Object.keys(style).forEach(function (key) {
|
||||
ta.style[key] = style[key];
|
||||
});
|
||||
|
||||
map['delete'](ta);
|
||||
}).bind(ta, {
|
||||
height: ta.style.height,
|
||||
resize: ta.style.resize,
|
||||
overflowY: ta.style.overflowY,
|
||||
overflowX: ta.style.overflowX,
|
||||
wordWrap: ta.style.wordWrap
|
||||
});
|
||||
|
||||
ta.addEventListener('autosize:destroy', destroy, false);
|
||||
|
||||
// IE9 does not fire onpropertychange or oninput for deletions,
|
||||
// so binding to onkeyup to catch most of those events.
|
||||
// There is no way that I know of to detect something like 'cut' in IE9.
|
||||
if ('onpropertychange' in ta && 'oninput' in ta) {
|
||||
ta.addEventListener('keyup', update, false);
|
||||
}
|
||||
|
||||
window.addEventListener('resize', pageResize, false);
|
||||
ta.addEventListener('input', update, false);
|
||||
ta.addEventListener('autosize:update', update, false);
|
||||
ta.style.overflowX = 'hidden';
|
||||
ta.style.wordWrap = 'break-word';
|
||||
|
||||
map.set(ta, {
|
||||
destroy: destroy,
|
||||
update: update
|
||||
});
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
function destroy(ta) {
|
||||
var methods = map.get(ta);
|
||||
if (methods) {
|
||||
methods.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
function update(ta) {
|
||||
var methods = map.get(ta);
|
||||
if (methods) {
|
||||
methods.update();
|
||||
}
|
||||
}
|
||||
|
||||
var autosize = null;
|
||||
|
||||
// Do nothing in Node.js environment and IE8 (or lower)
|
||||
if (typeof window === 'undefined' || typeof window.getComputedStyle !== 'function') {
|
||||
autosize = function (el) {
|
||||
return el;
|
||||
};
|
||||
autosize.destroy = function (el) {
|
||||
return el;
|
||||
};
|
||||
autosize.update = function (el) {
|
||||
return el;
|
||||
};
|
||||
} else {
|
||||
autosize = function (el, options) {
|
||||
if (el) {
|
||||
Array.prototype.forEach.call(el.length ? el : [el], function (x) {
|
||||
return assign(x, options);
|
||||
});
|
||||
}
|
||||
return el;
|
||||
};
|
||||
autosize.destroy = function (el) {
|
||||
if (el) {
|
||||
Array.prototype.forEach.call(el.length ? el : [el], destroy);
|
||||
}
|
||||
return el;
|
||||
};
|
||||
autosize.update = function (el) {
|
||||
if (el) {
|
||||
Array.prototype.forEach.call(el.length ? el : [el], update);
|
||||
}
|
||||
return el;
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = autosize;
|
||||
});
|