Skip to content
Permalink
Browse files

Fix small setup phanbook and add service slug

  • Loading branch information...
duythien committed Sep 8, 2019
1 parent 28c690b commit 2b922cf62f3a6887f63f548a0ad0bfb7d247787d
@@ -1,9 +1,10 @@
APPLICATION_ENV=local
PHP_DISPLAY_ERRORS=on

APP_REPO=https://github.com/phanbook
APP_SALT=put-some-secret-salt-here
APP_DEBUG=true
APP_URL=http://phanbook.dev
APP_URL=http://dev.phanbook.com
APP_BASE_URI=/
APP_STATIC_URL=/
APP_TIMEZONE=UTC
@@ -13,7 +14,7 @@ DB_USERNAME=phanbook
DB_PASSWORD=secret
DB_DATABASE=phanbook
DB_CHARSET=utf8
DB_HOST=localhost
DB_HOST=db
DB_CONNECTION=mysql

THEME_CODE=default
@@ -24,15 +25,15 @@ LANG_USE_GETTEXT=false
ANALYTIC_ID=
ANALYTIC_CLIENT_ID=
ANALYTIC_SECRET=
ANALYTIC_REDIRECT_URI=http://phanbook.dev/oauth/google/access_token
ANALYTIC_REDIRECT_URI=http://dev.phanbook.com/oauth/google/access_token

GITHUB_CLIENT_ID=
GITHUB_SECRET=
GITHUB_REDIRECT_URI=http://phanbook.dev/oauth/github/access_token
GITHUB_REDIRECT_URI=http://dev.phanbook.com/oauth/github/access_token

FACEBOOK_CLIENT_ID=
FACEBOOK_SECRET=
FACEBOOK_REDIRECT_URI=http://phanbook.dev/oauth/facebook/access_token
FACEBOOK_REDIRECT_URI=http://dev.phanbook.com/oauth/facebook/access_token

BEANSTALK_ENABLED=false
BEANSTALK_HOST=localhost
@@ -15,15 +15,7 @@
<div class="caption">
<h4>{{ user.getFullName() | capitalize }}</h4>
<p>Karma : {{ user.getHumanKarma()}}</p>
<p>Role:
{% if user.moderator === 'Y' %}
Moderator
{% elseif user.admin === 'Y' %}
Admin
{% else %}
Users
{% endif %}
</p>
<p>Role: </p>
<p>Joined on {{ date('M d,Y', user.getCreatedAt())}}</p>
</div>
</div>
@@ -13,7 +13,7 @@
namespace Phanbook\Common\Library\Providers;
use Phalcon\Mvc\Url;
use Phanbook\Utils\Slug;
/**
* \Phanbook\Common\Library\Providers\UrlResolverServiceProvider
*
@@ -57,5 +57,6 @@ function () {
return $url;
}
);
$this->di->setShared('slug', ['className' => Slug::class]);
}
}
@@ -19,48 +19,85 @@
*/
class Slug
{
protected $charMap = [
'À' => 'A', 'Ô' => 'O', 'Ď' => 'D', '' => 'F', 'Ë' => 'E', 'Š' => 'S', 'Ơ' => 'O',
'Ă' => 'A', 'Ř' => 'R', 'Ț' => 'T', 'Ň' => 'N', 'Ā' => 'A', 'Ķ' => 'K', 'Ĕ' => 'E',
'Ŝ' => 'S', '' => 'Y', 'Ņ' => 'N', 'Ĺ' => 'L', 'Ħ' => 'H', '' => 'P', 'Ó' => 'O',
'Ú' => 'U', 'Ě' => 'E', 'É' => 'E', 'Ç' => 'C', '' => 'W', 'Ċ' => 'C', 'Õ' => 'O',
'' => 'S', 'Ø' => 'O', 'Ģ' => 'G', 'Ŧ' => 'T', 'Ș' => 'S', 'Ė' => 'E', 'Ĉ' => 'C',
'Ś' => 'S', 'Î' => 'I', 'Ű' => 'U', 'Ć' => 'C', 'Ę' => 'E', 'Ŵ' => 'W', '' => 'T',
'Ū' => 'U', 'Č' => 'C', 'Ö' => 'O', 'È' => 'E', 'Ŷ' => 'Y', 'Ą' => 'A', 'Ł' => 'L',
'Ų' => 'U', 'Ů' => 'U', 'Ş' => 'S', 'Ğ' => 'G', 'Ļ' => 'L', 'Ƒ' => 'F', 'Ž' => 'Z',
'' => 'W', '' => 'B', 'Å' => 'A', 'Ì' => 'I', 'Ï' => 'I', '' => 'D', 'Ť' => 'T',
'Ŗ' => 'R', 'Ä' => 'A', 'Í' => 'I', 'Ŕ' => 'R', 'Ê' => 'E', 'Ü' => 'U', 'Ò' => 'O',
'Ē' => 'E', 'Ñ' => 'N', 'Ń' => 'N', 'Ĥ' => 'H', 'Ĝ' => 'G', 'Đ' => 'D', 'Ĵ' => 'J',
'Ÿ' => 'Y', 'Ũ' => 'U', 'Ŭ' => 'U', 'Ư' => 'U', 'Ţ' => 'T', 'Ý' => 'Y', 'Ő' => 'O',
'Â' => 'A', 'Ľ' => 'L', '' => 'W', 'Ż' => 'Z', 'Ī' => 'I', 'Ã' => 'A', 'Ġ' => 'G',
'' => 'M', 'Ō' => 'O', 'Ĩ' => 'I', 'Ù' => 'U', 'Į' => 'I', 'Ź' => 'Z', 'Á' => 'A',
'Û' => 'U', 'Þ' => 'Th', 'Ð' => 'Dh', 'Æ' => 'Ae', 'İ' => 'I', 'А' => 'A', 'Б' => 'B',
'В' => 'V', 'Г' => 'G', 'Д' => 'D', 'Е' => 'E', 'Ё' => 'E', 'Ж' => 'Z', 'З' => 'Z',
'И' => 'I', 'Й' => 'I', 'К' => 'K', 'Л' => 'L', 'М' => 'M', 'Н' => 'N', 'О' => 'O',
'П' => 'P', 'Р' => 'R', 'С' => 'S', 'Т' => 'T', 'У' => 'U', 'Ф' => 'F', 'Х' => 'H',
'Ц' => 'C', 'Ч' => 'C', 'Ш' => 'S', 'Щ' => 'S', 'Ъ' => '', 'Ь' => "", 'Ы' => 'Y',
'Э' => 'E', 'Ю' => 'U', 'Я' => 'A',
'à' => 'a', 'ô' => 'o', 'ď' => 'd', '' => 'f', 'ë' => 'e', 'š' => 's', 'ơ' => 'o',
'ß' => 'ss', 'ă' => 'a', 'ř' => 'r', 'ț' => 't', 'ň' => 'n', 'ā' => 'a', 'ķ' => 'k',
'ŝ' => 's', '' => 'y', 'ņ' => 'n', 'ĺ' => 'l', 'ħ' => 'h', '' => 'p', 'ó' => 'o',
'ú' => 'u', 'ě' => 'e', 'é' => 'e', 'ç' => 'c', '' => 'w', 'ċ' => 'c', 'õ' => 'o',
'' => 's', 'ø' => 'o', 'ģ' => 'g', 'ŧ' => 't', 'ș' => 's', 'ė' => 'e', 'ĉ' => 'c',
'ś' => 's', 'î' => 'i', 'ű' => 'u', 'ć' => 'c', 'ę' => 'e', 'ŵ' => 'w', '' => 't',
'ū' => 'u', 'č' => 'c', 'ö' => 'o', 'è' => 'e', 'ŷ' => 'y', 'ą' => 'a', 'ł' => 'l',
'ų' => 'u', 'ů' => 'u', 'ş' => 's', 'ğ' => 'g', 'ļ' => 'l', 'ƒ' => 'f', 'ž' => 'z',
'' => 'w', '' => 'b', 'å' => 'a', 'ì' => 'i', 'ï' => 'i', '' => 'd', 'ť' => 't',
'ŗ' => 'r', 'ä' => 'a', 'í' => 'i', 'ŕ' => 'r', 'ê' => 'e', 'ü' => 'u', 'ò' => 'o',
'ē' => 'e', 'ñ' => 'n', 'ń' => 'n', 'ĥ' => 'h', 'ĝ' => 'g', 'đ' => 'd', 'ĵ' => 'j',
'ÿ' => 'y', 'ũ' => 'u', 'ŭ' => 'u', 'ư' => 'u', 'ţ' => 't', 'ý' => 'y', 'ő' => 'o',
'â' => 'a', 'ľ' => 'l', '' => 'w', 'ż' => 'z', 'ī' => 'i', 'ã' => 'a', 'ġ' => 'g',
'' => 'm', 'ō' => 'o', 'ĩ' => 'i', 'ù' => 'u', 'į' => 'i', 'ź' => 'z', 'á' => 'a',
'û' => 'u', 'þ' => 'th', 'ð' => 'dh', 'æ' => 'ae', 'µ' => 'u', 'ĕ' => 'e', 'ı' => 'i',
'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd', 'е' => 'e', 'ё' => 'e',
'ж' => 'z', 'з' => 'z', 'и' => 'i', 'й' => 'i', 'к' => 'k', 'л' => 'l', 'м' => 'm',
'н' => 'n', 'о' => 'o', 'п' => 'p', 'р' => 'r', 'с' => 's', 'т' => 't', 'у' => 'u',
'ф' => 'f', 'х' => 'h', 'ц' => 'c', 'ч' => 'c', 'ш' => 's', 'щ' => 's', 'ъ' => '',
'ь' => "", 'ы' => 'y', 'э' => 'e', 'ю' => 'u', 'я' => 'a',
];
/**
* Creates a slug to be used for pretty URLs.
* Creates a slug to be used for pretty URLs
*
* @link http://cubiq.org/the-perfect-php-clean-url-generator
* @param $string
* @param array $replace
* @param string $delimiter
* @return mixed
* @throws \Phalcon\Exception
* @param string $string String for transliterate
* @param string $delimiter Delimiter [Optional]
* @return string
*/
public static function generate($string, $replace = array(), $delimiter = '-')
public function generate($string, $delimiter = '-')
{
if (!extension_loaded('iconv')) {
throw new \Phalcon\Exception('iconv module not loaded');
}
// Save the old locale and set the new locale to UTF-8
$oldLocale = setlocale(LC_ALL, '0');
setlocale(LC_ALL, 'en_US.UTF-8');
// Better to replace given $replace array as index => value
// Example $replace['ı' => 'i', 'İ' => 'i'];
if (!empty($replace) && is_array($replace)) {
$string = str_replace(array_keys($replace), array_values($replace), $string);
$method = $this->getTransliterateMethod();
$string = $this->{$method}($string);
$string = preg_replace('#[^\\pL\d]+#u', $delimiter, $string);
$string = preg_replace('#[-\s]+#', $delimiter, $string);
$string = preg_replace('#^[-\s]+#', '', $string);
$string = preg_replace('#[-\s]+$#', '', $string);
return trim($string, $delimiter);
}
protected function transliterateViaIntl($string)
{
$string = transliterator_transliterate('Any-Latin; Latin-ASCII; [:Punctuation:] Remove; Lower()', $string);
$string = preg_replace('#[^a-z0-9\/_|+\s-]#i', '', $string);
return preg_replace('#[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+#S', '', $string);
}
protected function transliterateViaCharMap($string)
{
$string = str_replace(array_keys($this->charMap), array_values($this->charMap), $string);
$string = preg_replace('#[[:punct:]]+#', '', $string);
$string = preg_replace('#[^a-z0-9\/_|+\s-]#i', '', $string);
$string = strtolower($string);
return preg_replace('#[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+#S', '', $string);
}
protected function getTransliterateMethod()
{
if (function_exists('transliterator_transliterate')) {
return 'transliterateViaIntl';
} else {
return 'transliterateViaCharMap';
}
// replace non letter or non digits by -
$string = preg_replace("#[^\\pL\d]+#u", '-', $string);
// Trim trailing -
$string = trim($string, '-');
$clean = iconv('UTF-8', 'ASCII//TRANSLIT', $string);
$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
$clean = strtolower($clean);
$clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);
$clean = trim($clean, $delimiter);
// Revert back to the old locale
setlocale(LC_ALL, $oldLocale);
return $clean;
}
}
@@ -152,7 +152,7 @@ public function columnMap()
/**
* Overwrite messages
*/
public function getMessages()
public function getMessages($filter = NULL)
{
$messages = array();
foreach (parent::getMessages() as $message) {
@@ -74,7 +74,7 @@
* It is strongly recommended that plugin and theme developers use
* in their development environments.
*/
'debug' => env('APP_DEBUG'),
'debug' => true,
/**
* Set the password hashing factor
@@ -136,7 +136,7 @@ public function saveAction()
} else {
$object = new Posts();
}
$object->setSlug(Slug::generate($this->request->getPost('title')));
$object->setSlug($this->slug->generate($this->request->getPost('title')));
$object->setUsersId($this->auth->getUserId());
$object->setType(Posts::POST_PAGE);
$form = new PostsForm($object);
@@ -16,7 +16,6 @@
use Phanbook\Backend\Forms\StickyForm;
use Phanbook\Backend\Forms\PostsForm;
use Phanbook\Models\Posts;
use Phanbook\Utils\Slug;
use Phanbook\Utils\Editor;
/**
@@ -228,7 +227,7 @@ public function saveAction()
$object = new Posts();
//@todo
}
$object->setSlug(Slug::generate($this->request->getPost('title')));
$object->setSlug$this->slug->generate($this->request->getPost('title')));
$object->setUsersId($this->auth->getUserId());
$form = new PostsForm($object);
$form->bind($_POST, $object);
@@ -12,7 +12,6 @@
*/
namespace Phanbook\Frontend\Controllers;
use Phanbook\Utils\Slug;
use Phanbook\Models\Vote;
use Phanbook\Utils\Editor;
use Phanbook\Models\Posts;
@@ -213,7 +212,7 @@ public function saveAction()
if (!empty($id)) {
$object = Posts::findFirstById($id);
$object->setSlug(Slug::generate($this->request->getPost('title')));
$object->setSlug($this->slug->generate($this->request->getPost('title')));
// @Todo continue When moderator or admin edit post
// Just to save history when user is TrustModerator and the user not owner the post
if ($this->auth->isTrustModeration() && $this->auth->getUserId() != $object->getUsersId()) {
@@ -229,7 +228,7 @@ public function saveAction()
} else {
$object = new Posts();
$object->setType(Posts::POST_QUESTIONS);
$object->setSlug(Slug::generate($this->request->getPost('title')));
$object->setSlug($this->slug->generate($this->request->getPost('title')));
$object->setUsersId($this->auth->getUserId());
$user = Users::findFirstById($this->auth->getUserId());
@@ -0,0 +1,55 @@
version: '3.3'

services:
db:
image: mysql:8.0.17
volumes:
- db_data:/var/lib/mysql
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: phanbook
MYSQL_USER: phanbook
MYSQL_PASSWORD: secret
ports:
- 3307:3306
php:
depends_on:
- db
- redis
image: gsviec/php:7.3-alpine
ports:
- "8080:80"
volumes:
- ./:/app
env_file:
- .env
nginx:
depends_on:
- php
image: nginx
ports:
- "80:80"
working_dir: /var/www/phanbook
volumes:
- ./:/var/www/phanbook
- ./docker/phanbook.conf:/etc/nginx/conf.d/default.conf
phpmyadmin:
restart: 'no'
image: phpmyadmin/phpmyadmin:4.6
depends_on:
- db
ports:
- "9090:80"
environment:
PMA_ARBITRARY: 1
PMA_HOST: db
PMA_PORT: 3306
PMA_USER: root
PMA_PASSWORD: secret
redis:
image: redis:alpine
ports:
- '6378:6379'
volumes:
db_data:
@@ -0,0 +1,58 @@
server {
listen 80 default_server;
server_name dev.phanbook.com;

index index.php index.html;
root /var/www/phanbook/public;

location / {
client_max_body_size 10m;
client_body_buffer_size 128k;

proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
proxy_connect_timeout 30s;
proxy_pass http://php:80;

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location ~* \.(eot|otf|ttf|woff|woff2)$ {
add_header Access-Control-Allow-Origin *;
}

location ~ /\.ht {
deny all;
}

location ^~ /core/assets/ {
root /var/www/phanbook;
}

location ^~ /content/themes/ {
root /var/www/phanbook;
}

location ^~ /content/modules/ {
root /var/www/phanbook;
}

location ~* /.*/assets/ {
root /var/www/phanbook/core/modules;
}

location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
root /var/www/phanbook/public;
}
##Right now it hard code:)
location /images/chrome.png {
root /var/www/phanbook/content/themes/default/assets;

}
}

0 comments on commit 2b922cf

Please sign in to comment.
You can’t perform that action at this time.