This commit is contained in:
Muhammad Iqbal Rifai 2018-03-28 12:11:18 +07:00
parent 6bf8d09fcc
commit f5b32f5c89
320 changed files with 62642 additions and 3 deletions

2
.gitattributes vendored
View File

@ -1,2 +0,0 @@
# Auto detect text files and perform LF normalization
* text=auto

View File

@ -1 +0,0 @@
# Horriblesubs

View File

0
css/fansub-plugin-admin.min.css vendored Normal file
View File

728
css/fansub-plugin.css Normal file
View File

@ -0,0 +1,728 @@
.fansub-new-release {
clear: both;
color: #333;
font-size: 16px;
line-height: 24px;
padding: 12px 0 0;
}
.fansub-new-release > h2.box-title {
border-bottom: 1px solid #ccc;
color: #000;
font-size: 22px;
font-weight: 400;
line-height: 1.5em;
margin: 0 0 20px;
}
.fansub-new-release .box-content a {
border: medium none;
text-decoration: none;
}
.fansub-new-release .list-qualities > li > .quality,
.fansub-new-release a:link {
-webkit-transition: all 0.2s ease-in-out 0s;
-moz-transition: all 0.2s ease-in-out 0s;
-ms-transition: all 0.2s ease-in-out 0s;
-o-transition: all 0.2s ease-in-out 0s;
transition: all 0.2s ease-in-out 0s;
}
.fansub-new-release .search-form {
font-weight: 700;
margin-bottom: 4px;
margin-top: -10px;
padding: 4px;
position: relative;
}
.fansub-new-release .search-form .searchcontainer {
margin: 0 auto;
width: 230px;
}
.fansub-new-release .search-form .search-field {
background-color: rgba(220, 220, 220, 0.7);
border: 0 solid #ccc;
font-family: Open Sans;
font-size: 14px !important;
height: 22px;
margin-bottom: 0 !important;
padding: 0 10px;
text-align: center;
width: 260px;
}
.fansub-new-release .search-form .btn-refresh {
display: inline-block;
font-weight: 400;
position: absolute;
right: 0;
top: 6px;
}
.fansub-new-release .search-form .btn-refresh a {
cursor: pointer;
}
.fansub-new-release .search-form .btn-refresh a:hover {
color: #777;
}
.entry-content .fansub-new-release ul,
.fansub-new-release ul {
list-style: outside none none;
margin: 0;
padding: 0;
}
.fansub-new-release ul.list-releases > li:after,
.fansub-new-release ul.list-releases > li:before,
.fansub-new-release ul:before,
.fansub-new-release ul:after {
clear: both;
content: " ";
display: table;
}
.fansub-new-release ul li {
box-shadow: none;
float: left;
margin: 0;
padding: 2px 0;
}
.fansub-new-release .list-releases > li {
display: block;
float: none;
margin: 0;
padding: 0;
position: relative;
}
.fansub-new-release .list-servers {
display: none;
}
.fansub-new-release .list-cols .col-date {
margin-right: 5px;
}
.fansub-new-release .list-cols .col-date,
.fansub-new-release .list-cols .suffix {
color: #707070;
}
.fansub-new-release .list-cols .col-title {
}
.fansub-new-release .list-cols .col-download {
float: right;
}
.fansub-new-release .list-cols .post-title-link {
border-bottom: 1px dotted #000;
}
.fansub-new-release .list-releases > li .list-servers > li a:hover,
.fansub-new-release .list-qualities > li > .quality.has-link:hover,
.fansub-new-release .list-cols .post-title-link:hover {
background-color: #aaa;
color: #fff;
}
.fansub-new-release .list-qualities > li {
margin-left: 5px;
padding: 0 2px;
}
.fansub-new-release .list-qualities > li > .quality.has-link {
cursor: pointer;
}
.fansub-new-release .morebox {
font-weight: 700;
margin-bottom: 4px;
margin-top: 4px;
padding: 4px;
text-align: center;
}
.fansub-new-release .morebox:hover {
background-color: #fee;
}
.fansub-new-release .morebox:hover a {
color: #333;
}
.fansub-new-release .list-qualities .quality-item .list-servers {
position: absolute;
right: 0;
text-align: right;
top: 100%;
width: 100%;
z-index: 499;
}
.fansub-new-release .list-qualities .quality-item .list-servers > li {
clear: none;
display: inline-block;
float: none;
padding: 0 2px;
}
.fansub-new-release .list-qualities .quality-item .list-servers > li.file-name {
color: #333;
float: left;
padding-left: 0;
}
.fansub-new-release .list-qualities .quality-item .list-servers > li span {
padding: 0 2px;
}
.fansub-new-release .list-releases > li.active {
margin-bottom: 25px;
}
.fansub-new-release .list-releases > li .list-servers > li {
color: #ddd;
}
.fansub-new-release .list-qualities .quality-item .quality {
color: #ddd;
}
.fansub-new-release .list-qualities .quality-item .quality.has-link {
color: #333;
}
.fansub-new-release a {
color: #333;
}
.fansub-new-release .series-image img {
float: left;
margin-bottom: 12px;
margin-right: 24px;
}
.fansub-new-release.single-box h2 {
border-bottom: 1px solid #ccc;
font-size: 25px;
font-weight: 400;
}
.fansub-new-release.single-box .tips {
background-color: rgba(220, 220, 220, 0.7);
display: block;
margin-bottom: 10px;
padding: 5px 10px;
}
.fansub-new-release .noselect {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.fansub-new-release .series-info {
overflow: hidden;
}
.fansub-new-release .comments-area li {
float: none;
}
.fansub-new-release .comments-area li .children {
margin-left: 50px;
margin-top: 20px;
}
.fansub-new-release .comments-area li .avatar {
vertical-align: top;
}
.fansub-new-release .comments-area li p {
margin-bottom: 10px;
}
.fansub-new-release .comments-area li p:last-of-type {
margin-bottom: 0;
}
.fansub-new-release .comments-area li .comment-body {
border-bottom: 1px solid #ddd;
padding-bottom: 10px;
}
.fansub-new-release.anime-list > h2 {
margin-bottom: 10px;
margin-top: 0;
}
.fansub-new-release.anime-list .pagination {
margin: 10px 0;
text-align: center;
}
.fansub-new-release.anime-list .pagination .item {
color: #3d3d3d;
font-size: 18px;
margin: 0 2px;
padding: 2px 10px;
text-decoration: none;
}
.fansub-new-release.anime-list .pagination .item.link-item:hover,
.fansub-new-release.anime-list .pagination .item.current-item {
background-color: #0075c1;
border-radius: 3px;
color: #fff;
}
.fansub-new-release .list-animes .fansub-post {
border-bottom: 2px solid #e2e2e2;
float: none;
overflow: hidden;
padding: 0;
}
.fansub-new-release .list-animes .fansub-post .entry-summary {
margin-left: 0;
}
.fansub-new-release .list-animes .fansub-post:last-child {
border-bottom: medium none;
}
.fansub-new-release .list-animes .fansub-post .anime-thumb {
float: left;
height: 196px;
margin-right: 20px;
position: relative;
width: 140px;
}
.fansub-new-release .list-animes .fansub-post .wp-post-image {
border-radius: 0;
box-shadow: none;
height: 32px;
width: 32px;
}
.fansub-new-release .anime-thumb .wp-post-image.lazyload {
height: 32px;
left: 50%;
margin: -16px 0 0 -16px;
position: absolute;
top: 50%;
width: 32px;
}
.fansub-new-release .list-animes .fansub-post .anime-thumb .wp-post-image.lazyloaded {
height: 100%;
width: 100%;
}
.fansub-new-release .list-animes .fansub-post .anime-thumb {
background: rgba(0, 0, 0, 0) url("../images/loading.gif") no-repeat scroll center center;
}
.fansub-new-release .list-animes .fansub-post .entry-title {
clear: none;
font-size: 21px;
margin-bottom: 5px;
margin-top: 0;
}
.fansub-new-release .list-animes .fansub-post .entry-title a {
color: #333;
text-decoration: none;
}
.fansub-new-release .list-animes .fansub-post .entry-title a:hover {
text-decoration: underline;
}
.fansub-new-release .list-animes .fansub-post .entry-summary {
color: #666;
font-size: 14px;
}
.fansub-new-release .list-animes .fansub-post .entry-summary p:last-child {
margin-bottom: 0;
}
.fansub-new-release .list-animes .fansub-post .more-link {
display: none;
}
.fansub-new-release.advanced-search .search-form {
margin: 0 auto;
max-width: 768px;
min-width: 400px;
overflow: hidden;
width: 80%;
}
.fansub-new-release.advanced-search .search-form .search-submit {
background: rgba(0, 0, 0, 0) url("../images/icon-search.png") no-repeat scroll center center / 32px auto;
border-radius: 0 8px 8px 0;
border-width: 1px 1px 1px 0;
float: left;
height: 48px;
min-width: 70px;
text-indent: -9999px;
width: 10%;
}
.fansub-new-release.advanced-search .search-form label {
display: inline-block;
float: left;
width: 80%;
}
.fansub-new-release.advanced-search .search-form .search-field {
background: rgba(0, 0, 0, 0) none repeat scroll 0 0;
border: 1px solid #ddd;
border-radius: 8px 0 0 8px;
color: #323232;
height: 48px;
text-align: left;
width: 100%;
}
.fansub-new-release.advanced-search .search-form .search-field {
box-sizing: border-box;
height: 48px;
}
.fansub-new-release.advanced-search .search-form .search-submit {
padding-bottom: 10px;
padding-top: 10px;
}
.fansub-new-release.advanced-search .search-form .search-field:hover,
.fansub-new-release.advanced-search .search-form .search-submit:hover {
border-color: #ddd;
}
.fansub-new-release.advanced-search .search-form .search-submit:hover {
background-color: #eee;
}
.ui-widget-content {
background-color: #ffffff;
border: 1px solid #bebebe !important;
border-radius: 0 0 6px 6px;
box-shadow: 0 10px 15px 5px rgba(0, 0, 0, 0.2);
display: none;
left: 0;
position: absolute;
top: 25px;
width: 277px;
z-index: 100;
}
.ui-widget-content .ui-menu-item {
background-color: #ffffff;
border-bottom: 1px solid #ebebeb;
overflow: hidden;
padding: 2px !important;
text-align: left;
}
.ui-widget-content .ui-menu-item.ui-sate-focus,
.ui-widget-content .ui-menu-item.focus,
.ui-widget-content .ui-menu-item:hover {
background-color: #e1e7f5;
background-image: none !important;
}
.ui-widget-content .ui-menu-item .list a > span {
display: none;
float: left;
margin-right: 5px;
}
.ui-widget-content .ui-menu-item .list a > span.thumb {
display: inline-block;
}
.ui-widget-content .ui-menu-item:hover .list a > span.thumb {
display: none;
}
.ui-widget-content .ui-menu-item:hover .list a > span.image {
display: inline-block;
}
.ui-widget-content .ui-menu-item .list a > span.thumb img {
height: 50px;
width: 70px;
}
.ui-widget-content .ui-menu-item .list a > span.image img {
height: 90px;
width: 70px;
}
.ui-widget-content .ui-menu-item .list a {
line-height: 22px;
text-decoration: none;
}
.ui-widget-content .ui-menu-item:last-child {
padding-bottom: 0 !important;
}
.fansub-new-release.advanced-search .module-body .search-results {
margin-top: 10px;
}
.fansub-new-release.advanced-search .module-body .search-results > h4 {
border-bottom: 1px solid #bebebe;
margin: 0 0 10px;
}
.fansub-new-release.single-box .video-box .fansub-post {
border: medium none;
display: inline-block;
height: 146px;
margin-bottom: 8px;
margin-right: 8px;
padding: 0;
position: relative;
vertical-align: top;
width: 260px;
}
.fansub-new-release.single-box .video-box .fansub-post .post-thumbnail {
display: block;
position: relative;
}
.fansub-new-release.single-box .video-box .fansub-post .wp-post-image {
border-radius: 0;
box-shadow: none;
height: 146px;
width: 260px;
}
.fansub-new-release.single-box .video-box .fansub-post .entry-title {
background-color: rgba(0, 0, 0, 0.5);
bottom: 0;
font-size: 13px;
left: 0;
margin: 0 !important;
padding: 5px;
position: absolute;
right: 0;
}
.fansub-new-release.single-box .video-box .fansub-post .entry-title a {
color: #fff;
text-decoration: none;
}
.fansub-new-release.single-box .video-box .fansub-post .icon-play {
border-radius: 8px;
height: 38px;
left: 50%;
margin-left: -45px;
margin-top: -19px;
position: absolute;
top: 50%;
width: 90px;
z-index: 399;
}
.fansub-new-release.single-box .video-box .fansub-post:hover {
opacity: 0.7;
}
.fansub-new-release.single-box .video-box .fansub-post {
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-ms-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
.fancybox-inner .wp-video .wp-video-shortcode,
.fancybox-inner .wp-video {
height: 480px !important;
margin: 0 auto;
width: 100% !important;
}
.fancybox-inner .wp-video .mejs-controls {
width: 100% !important;
}
.fancybox-inner iframe,
.fancybox-inner .wp-video .wp-video-shortcode {
background-color: #000;
}
.fancybox-inner iframe {
height: 60%;
width: 100%;
}
.fansub-new-release.fansub-single .series-releases .video-box .bx-controls .bx-pager {
display: none;
}
.fansub-new-release.fansub-single .series-releases .video-box .bx-wrapper {
margin-bottom: 10px;
}
.fansub-new-release.fansub-single .series-releases .video-box .bx-wrapper .bx-viewport {
box-shadow: none;
}
.fansub-new-release.fansub-single .series-releases .video-box .bx-wrapper .bx-viewport .module-body {
}
.fansub-new-release.fansub-single .series-releases .video-box .bx-wrapper .bx-controls .bx-controls-direction a {
background-image: url("../images/btn-slider-control.png");
background-position: 0 0;
background-repeat: no-repeat;
background-size: 80px auto;
cursor: pointer;
display: inline-block;
height: 80px;
margin-top: -40px;
opacity: 0;
overflow: hidden;
position: absolute;
top: 50%;
transition-duration: 0.3s;
transition-property: all;
transition-timing-function: ease-in-out;
width: 40px;
z-index: 10;
}
.fansub-new-release.fansub-single .series-releases .video-box .bx-wrapper .bx-controls .bx-controls-direction a.bx-prev {
background-position: -40px 0;
left: -40px;
opacity: 0;
}
.fansub-new-release.fansub-single .series-releases .video-box .bx-wrapper .bx-controls .bx-controls-direction a.bx-next {
background-position: 0 0;
opacity: 0;
right: -40px;
}
.fansub-new-release.fansub-single .series-releases .video-box .bx-wrapper:hover .bx-controls .bx-controls-direction a.bx-prev {
left: 0;
opacity: 1;
}
.fansub-new-release.fansub-single .series-releases .video-box .bx-wrapper:hover .bx-controls .bx-controls-direction a.bx-next {
opacity: 1;
right: 0;
}
.fancybox-wrap .video-js,
.fancybox-wrap p video,
.video-box .video-js,
.video-box video {
height: 100%;
width: 100%;
}
.fancybox-inner > div > div:not(.center), .fancybox-inner > div > div > .jwplayer {
height: 480px !important;
margin: 0 !important;
width: 100% !important;
}
.fancybox-inner > div > div > .jwplayer.jw-flag-fullscreen .jw-stretch-uniform,
.fancybox-inner > div > div > .jwplayer.jw-flag-fullscreen {
height: 100% !important;
}
@media only screen and (max-width: 640px) {
}
@media only screen and (max-width: 620px) {
.fansub-new-release .list-cols > li {
display: inline-block;
float: none;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.fansub-new-release .list-cols > li:nth-child(2) {
max-width: 50%;
}
.fansub-new-release .list-qualities .quality-item .list-servers > li.file-name {
display: none;
}
}
@media only screen and (max-width: 600px) {
}
@media only screen and (max-width: 568px) {
}
@media only screen and (max-width: 563px) {
}
@media only screen and (max-width: 549px) {
}
@media only screen and (max-width: 534px) {
}
@media only screen and (max-width: 480px) {
.fansub-new-release .list-qualities > li {
padding: 0;
}
.fansub-new-release .list-cols > li:nth-child(2) {
max-width: 35%;
}
}
@media only screen and (max-width: 360px) {
.fansub-new-release .list-cols .col-date {
display: none;
}
.fansub-new-release .list-cols > li:nth-child(2) {
max-width: 45%;
}
}
@media only screen and (max-width: 338px) {
}
@media only screen and (max-width: 330px) {
}
@media only screen and (max-width: 320px) {
}

1
css/fansub-plugin.min.css vendored Normal file

File diff suppressed because one or more lines are too long

2
css/index.php Normal file
View File

@ -0,0 +1,2 @@
<?php
# Silence is golden.

View File

@ -0,0 +1,108 @@
<?php
if (!function_exists('add_filter')) exit;
if (!fansub_kntl_license_valid()) {
return;
}
function hocwp_ph_admin_option()
{
global $hocwp_pos_tabs;
$defaults = fansub_kntl_get_option_defaults();
$option = new FANSUB_Option('HorribleSubs', 'fansub_kntl');
$option->set_parent_slug('hocwp_plugin_option');
$option->set_use_style_and_script(true);
$option->set_use_media_upload(true);
$options = $option->get();
$option->add_field(array('id' => 'test_upload', 'title' => 'Test upload', 'field_callback' => 'hocwp_field_media_upload'));
$option->add_field(array('id' => 'single_page', 'title' => 'Single Page', 'default' => $defaults['single_page'], 'field_callback' => 'hocwp_field_select_page'));
$option->add_field(array('id' => 'posts_per_page', 'title' => 'Post Number', 'default' => $defaults['posts_per_page'], 'field_callback' => 'hocwp_field_input_number'));
$option->add_field(array('id' => 'date_format', 'title' => 'Date Format', 'default' => $defaults['date_format']));
$option->add_field(array('id' => 'loading_text', 'title' => 'Loading Text', 'default' => $defaults['loading_text']));
$option->add_field(array('id' => 'search_none_text', 'title' => 'No Result Text', 'default' => $defaults['search_none_text']));
$option->add_field(array('id' => 'show_more_text', 'title' => 'Show More Text', 'default' => $defaults['show_more_text']));
$option->add_field(array('id' => 'reached_end_text', 'title' => 'Reached End Text', 'default' => $defaults['reached_end_text']));
$option->add_field(array('id' => 'clear_text', 'title' => 'Clear Text', 'default' => $defaults['clear_text']));
$option->add_field(array('id' => 'refresh_text', 'title' => 'Refresh Text', 'default' => $defaults['refresh_text']));
$option->add_field(array('id' => 'qualities', 'title' => 'Qualities', 'default' => $defaults['qualities'], 'description' => 'Separate qualities with commas.'));
$option->add_field(array('id' => 'servers', 'title' => 'Servers', 'default' => $defaults['servers'], 'description' => 'Separate servers with commas.'));
$option->add_section(array('id' => 'post_type', 'title' => 'Post Type', 'description' => 'Post type informations, if all fields are empty, the default post type will be used.'));
$option->add_field(array('id' => 'post_type_name', 'title' => 'Name', 'default' => $defaults['post_type_name'], 'section' => 'post_type'));
$option->add_field(array('id' => 'post_type_label_name', 'title' => 'Label Name', 'default' => $defaults['post_type_label_name'], 'section' => 'post_type'));
$option->add_field(array('id' => 'post_type_label_singular_name', 'title' => 'Label Singular Name', 'default' => $defaults['post_type_label_singular_name'], 'section' => 'post_type'));
$option->add_section(array('id' => 'release_box', 'title' => 'Release Box', 'description' => 'All settings for release box.'));
$option->add_field(array('id' => 'release_box_title', 'title' => 'Title', 'default' => $defaults['release_box_title'], 'section' => 'release_box'));
$option->add_field(array('id' => 'release_box_search_placeholder', 'title' => 'Search Placeholder', 'default' => $defaults['release_box_search_placeholder'], 'section' => 'release_box'));
$option->add_section(array('id' => 'single_box', 'title' => 'Single Box', 'description' => 'All settings for post box on single page.'));
$option->add_field(array('id' => 'single_batch_title', 'title' => 'Batch Title', 'default' => $defaults['single_batch_title'], 'section' => 'single_box'));
$option->add_field(array('id' => 'single_batch_tip', 'title' => 'Batch Tips', 'default' => $defaults['single_batch_tip'], 'section' => 'single_box'));
$option->add_field(array('id' => 'single_batch_none', 'title' => 'No Batch Text', 'default' => $defaults['single_batch_none'], 'section' => 'single_box'));
$option->add_field(array('id' => 'single_search_placeholder', 'title' => 'Search Placeholder', 'default' => $defaults['single_search_placeholder'], 'section' => 'single_box'));
$option->add_field(array('id' => 'single_episode_none', 'title' => 'No Episode Text', 'default' => $defaults['single_episode_none'], 'section' => 'single_box'));
$option->add_section(array('id' => 'facebook', 'title' => 'Facebook', 'description' => 'Provide your information to connect with Facebook.'));
$post_type = isset($options['fb_post_type']) ? $options['fb_post_type'] : '';
$post_type = hocwp_json_string_to_array($post_type);
if (!hocwp_array_has_value($post_type)) {
$post_type = array();
}
$lists = get_post_types(array('_builtin' => false, 'public' => true), 'objects');
if (!array_key_exists('post', $lists)) {
$lists[] = get_post_type_object('post');
}
//$lists[] = get_post_type_object('episode');
//$lists[] = get_post_type_object('batch');
$all_option = '';
foreach ($lists as $lvalue) {
$selected = '';
foreach ($post_type as $ptvalue) {
$ptype = isset($ptvalue['value']) ? $ptvalue['value'] : '';
if ($lvalue->name == $ptype) {
$selected = $lvalue->name;
break;
}
}
$args = array(
'value' => $lvalue->name,
'text' => $lvalue->labels->singular_name,
'selected' => $selected
);
$all_option .= hocwp_field_get_option($args);
}
$args = array(
'id' => 'fb_post_type',
'name' => 'fb_post_type',
'all_option' => $all_option,
'value' => $post_type,
'title' => 'Post type',
'placeholder' => 'Choose post types',
'multiple' => true,
'field_callback' => 'hocwp_field_select_chosen',
'section' => 'facebook'
);
$option->add_field($args);
$option->add_field(array('id' => 'fb_app_id', 'title' => 'App ID', 'section' => 'facebook'));
$option->add_field(array('id' => 'fb_app_secret', 'title' => 'App Secret', 'section' => 'facebook'));
$option->add_field(array('id' => 'fb_redirect_uri', 'title' => 'Redirect Uri', 'section' => 'facebook'));
$option->add_field(array('id' => 'fb_access_token', 'title' => 'Access Token', 'section' => 'facebook'));
$option->add_option_tab($hocwp_pos_tabs);
$option->set_page_header_callback('hocwp_plugin_option_page_header');
$option->set_page_footer_callback('hocwp_plugin_option_page_footer');
$option->set_page_sidebar_callback('hocwp_plugin_option_page_sidebar');
$option->init();
hocwp_option_add_object_to_list($option);
}
add_action('init', 'hocwp_ph_admin_option');

View File

@ -0,0 +1,485 @@
<?php
if (!function_exists('add_filter')) exit;
if (!fansub_kntl_license_valid()) {
return;
}
function fansub_search_autocomplete_ajax_callback()
{
$term = isset($_REQUEST['term']) ? $_REQUEST['term'] : '';
$suggestions = array();
$args = array(
'post_type' => fansub_kntl_get_post_type(),
's' => $term,
'posts_per_page' => 10
);
$query = fansub_query($args);
$defaults = fansub_kntl_get_option_defaults();
$option_data = fansub_kntl_get_option();
$option_data = wp_parse_args($option_data, $defaults);
$single_page = fansub_get_value_by_key($option_data, 'single_page');
while ($query->have_posts()) {
$query->the_post();
$thumbnail_url = fansub_get_post_thumbnail_url();
$image_url = bfi_thumb($thumbnail_url, array('width' => 70, 'height' => 90, 'crop' => true));
$thumb_url = bfi_thumb($thumbnail_url, array('width' => 70, 'height' => 50, 'crop' => true));
$permalink = fansub_kntl_build_single_url($single_page, get_the_ID());
ob_start();
?>
<div data-url="<?php echo $permalink; ?>" class="list">
<a class="clearfix" href="<?php echo $permalink; ?>">
<span class="image"><img src="<?php echo $image_url; ?>"></span>
<span class="thumb"><img src="<?php echo $thumb_url; ?>"></span>
<div class="info">
<span class="text add-text"><?php the_title(); ?></span>
</div>
</a>
</div>
<?php
$post_html = ob_get_clean();
$suggestion = array(
'label' => get_the_title(),
'link' => get_permalink(),
'html' => $post_html
);
$suggestions[] = $suggestion;
}
wp_reset_postdata();
if ($query->have_posts()) {
$suggestion = array(
'label' => 'View more',
'link' => get_search_link($term)
);
$suggestions[] = $suggestion;
}
echo json_encode($suggestions);
exit;
}
add_action('wp_ajax_fansub_search_autocomplete', 'fansub_search_autocomplete_ajax_callback');
add_action('wp_ajax_nopriv_fansub_search_autocomplete', 'fansub_search_autocomplete_ajax_callback');
function fansub_kntl_video_list_ajax_callback()
{
$post_id = isset($_POST['post_id']) ? $_POST['post_id'] : 0;
$jwplayer = isset($_POST['jwplayer']) ? $_POST['jwplayer'] : false;
$result = array(
'have_posts' => false,
'has_data' => false
);
$html_data = '';
if (!(bool)$jwplayer) {
$video = fansub_query_post_by_meta('animation', $post_id, array('post_type' => 'video', 'posts_per_page' => -1), 'numeric');
$result['have_posts'] = $video->have_posts();
while ($video->have_posts()) {
$video->the_post();
$id = get_the_ID();
$fancy_id = 'videoBox' . $id;
$jwplayer_video_url = get_post_meta($id, '_jwppp-video-url-1', true);
ob_start();
$article = '<article ';
ob_start();
post_class('');
$article .= ob_get_clean();
$article .= ' data-id="' . get_the_ID() . '"';
if (current_theme_supports('fansub-schema')) {
ob_start();
fansub_html_tag_attributes('article', 'post');
$article .= ob_get_clean();
}
if (!empty($jwplayer_video_url)) {
$article .= ' data-jwplayer="1"';
} else {
$article .= ' data-jwplayer="0"';
}
$article .= '>';
$article = apply_filters('fansub_article_before', $article);
echo $article;
$custom_html = '<a href="#' . $fancy_id . '" class="fancy-link"><img class="icon-play" src="' . FANSUB_KNTL_URL . '/images/icon-play.png' . '"></a>';
fansub_post_thumbnail(array('width' => 260, 'height' => 146, 'crop' => true, 'custom_html' => $custom_html, 'permalink' => '#' . $fancy_id));
//fansub_post_title_link();
?>
<div id="<?php echo $fancy_id; ?>" class="video-fancy-box" style="display: none">
<?php
$only_member = get_post_meta($id, 'only_member', true);
if ((bool)$only_member) {
$actual_link = fansub_get_current_url();
if (is_user_logged_in()) {
the_content();
} else {
?>
<div class="center"
style="position: absolute; top: 40%; left: 50%; width: 220px; margin-left: -110px;">
<p>Bạn cần <a href="<?php echo wp_login_url($actual_link); ?>">login</a> để xem video này.
</p>
</div>
<?php
}
} else {
the_content();
}
?>
</div>
<?php
fansub_article_after();
$html_data .= ob_get_clean();
}
wp_reset_postdata();
} else {
$page = fansub_get_page_by_template('../jwplayer.php');
if (is_a($page, 'WP_Post')) {
$url = get_permalink($page);
$url = add_query_arg(array('post_id' => $post_id), $url);
$html_data = '<iframe src="' . $url . '" allowfullscreen webkitallowfullscreen mozallowfullscreen>';
$result['has_data'] = true;
}
}
$result['html_data'] = $html_data;
echo json_encode($result);
exit;
}
add_action('wp_ajax_fansub_kntl_video_list', 'fansub_kntl_video_list_ajax_callback');
add_action('wp_ajax_nopriv_fansub_kntl_video_list', 'fansub_kntl_video_list_ajax_callback');
function fansub_kntl_search_post_ajax_callback()
{
$refresh = isset($_POST['refresh']) ? $_POST['refresh'] : 0;
$default_query_vars = isset($_POST['default_query_vars']) ? $_POST['default_query_vars'] : array();
$default_query_vars = fansub_json_string_to_array($default_query_vars);
$box_type = isset($_POST['box_type']) ? $_POST['box_type'] : 'all';
$query_vars = isset($_POST['query_vars']) ? $_POST['query_vars'] : array();
$query_vars = fansub_json_string_to_array($query_vars);
$data = isset($_POST['options_data']) ? $_POST['options_data'] : array();
$data = fansub_json_string_to_array($data);
$load_more = isset($_POST['load_more']) ? $_POST['load_more'] : 0;
$search = isset($_POST['search']) ? $_POST['search'] : '';
$is_search = isset($_POST['is_search']) ? $_POST['is_search'] : 0;
$single = isset($_POST['single']) ? $_POST['single'] : 0;
if ((bool)$refresh) {
$query_vars = $default_query_vars;
}
$result = array(
'success' => false,
'more_post' => true
);
$data_post_not_in = fansub_get_value_by_key($query_vars, 'post__not_in');
if (!(bool)$load_more) {
if (!empty($search)) {
$query_vars['s'] = $search;
unset($query_vars['post__not_in']);
} else {
unset($query_vars['s']);
}
}
if ((bool)$is_search) {
$query_vars['s'] = $search;
}
$post_types = fansub_get_value_by_key($query_vars, 'post_type', 'episode');
$post_types = fansub_sanitize_array($post_types);
$date_format = isset($data['date_format']) ? $data['date_format'] : 'm/d';
$post_type = fansub_kntl_get_post_type();
$option_data = fansub_kntl_get_option();
$single_page = fansub_get_value_by_key($option_data, 'single_page');
if (fansub_array_has_value($default_query_vars)) {
$query_vars = $default_query_vars;
}
if ((bool)$refresh) {
//unset($query_vars['post__not_in']);
}
$query_args = $query_vars;
if ((bool)$is_search) {
$query_args['post_type'] = array('episode', 'batch');
if ('batch' == $box_type) {
$query_args['post_type'] = array('batch');
}
}
$query = fansub_query($query_args);
$post_count = $query->post_count;
$posts_per_page = $query->query_vars['posts_per_page'];
$html_items = '';
$post_not_in = $query->query_vars['post__not_in'];
$query_vars = $query->query_vars;
$result['have_posts'] = $query->have_posts();
$result['post_count'] = $post_count;
$result['posts_per_page'] = $posts_per_page;
if ($post_count < $posts_per_page) {
$result['more_post'] = false;
}
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$post_id = get_the_ID();
$post = get_post(get_the_ID());
$post_not_in[] = $post->ID;
$post_title = $post->post_title;
$post_link = '#';
$suffix = '';
$parts = array();
if ('episode' == $post->post_type) {
$parts = fansub_kntl_convert_post_title_to_parts($post->post_title);
array_shift($parts);
$parts = array_map('trim', $parts);
$animation_id = get_post_meta($post->ID, 'animation', true);
$animation = get_post($animation_id);
if (is_a($animation, 'WP_Post')) {
$post_title = $animation->post_title;
$post_link = fansub_kntl_build_single_url($single_page, $animation_id);
if (!fansub_array_has_value($parts)) {
}
$part = array_pop($parts);
if (!empty($part)) {
$suffix = '<span class="suffix">' . ' - ' . $part . '</span>';
}
}
// Giu nguyen episode title
if ((bool)$single) {
$post_title = $post->post_title;
$post_link = '#';
}
} elseif ('batch' == $post->post_type) {
$parts = fansub_kntl_convert_post_title_to_parts($post->post_title);
array_shift($parts);
$parts = array_map('trim', $parts);
$episode_id = get_post_meta($post->ID, 'episode', true);
if (is_numeric($episode_id) && $episode_id > 0) {
$animation_id = get_post_meta($episode_id, 'animation', true);
$animation = get_post($animation_id);
if (is_a($animation, 'WP_Post')) {
$post_title = $animation->post_title;
$post_link = fansub_kntl_build_single_url($single_page, $animation_id);
if (!fansub_array_has_value($parts)) {
}
$part = array_pop($parts);
if (!empty($part)) {
$tmp_part = array_pop($parts);
if (!empty($tmp_part)) {
$part = $tmp_part . '-' . $part;
}
$suffix = '<span class="suffix">' . ' - ' . $part . '</span>';
}
}
} else {
$animation_id = get_post_meta($post->ID, 'animation', true);
$animation = get_post($animation_id);
if (is_a($animation, 'WP_Post')) {
$post_title = $animation->post_title;
$post_link = fansub_kntl_build_single_url($single_page, $animation_id);
if (!fansub_array_has_value($parts)) {
}
$part = array_pop($parts);
if (!empty($part)) {
$tmp_part = array_pop($parts);
if (!empty($tmp_part)) {
$part = $tmp_part . '-' . $part;
}
$suffix = '<span class="suffix">' . ' - ' . $part . '</span>';
}
}
}
if ('batch' == $box_type || 'release' == $box_type) {
$post_title = $post->post_title;
}
} else {
$post_title = $post->post_title;
$post_link = fansub_kntl_build_single_url($single_page, $post->ID);
}
$link_html = new FANSUB_HTML('a');
if ((bool)$single) {
$link_html->use_only_text();
$post_title = '<span class="post-title-link">' . $post_title . '</span>';
}
$link_html->set_href($post_link);
$link_html->set_text($post_title);
$link_html->set_class('post-title-link');
$saved_suffix = get_post_meta($post->ID, 'suffix', true);
if ('batch' == $box_type || ('release' == $box_type && 'batch' == $post->post_type)) {
$suffix = '';
}
if (!empty($saved_suffix)) {
$suffix = '<span class="suffix">' . ' - ' . $saved_suffix . '</span>';
}
$post_title_text = $link_html->build();
if (!(bool)$single) {
$post_title_text .= $suffix;
}
$qs = fansub_ph_get_qualities_and_servers(get_the_ID());
$qualities = $qs['qualities'];
$servers = $qs['servers'];
ob_start();
?>
<li <?php post_class(sanitize_html_class($post->post_type)); ?>>
<ul class="list-cols">
<li class="col-date"><span class="post-date">(<?php echo get_the_date($date_format); ?>)</span></li>
<li class="col-title"><span class="post-title"><?php echo $post_title_text; ?></span></li>
<li class="col-download">
<ul class="list-qualities">
<?php foreach ($qualities as $quality) : ?>
<?php
$file_name_key = 'quality_' . $quality . '_file_name';
$file_name = get_post_meta($post->ID, $file_name_key, true);
if (empty($file_name)) {
if ('episode' == $post->post_type) {
$ep_am_id = get_post_meta($post->ID, 'animation', true);
if (fansub_id_number_valid($ep_am_id)) {
$ep_am = get_post($ep_am_id);
$file_name = $ep_am->post_title . ' [' . $quality . ']';
}
} elseif ('batch' == $post->post_type) {
$bt_ep_id = get_post_meta($post->ID, 'episode', true);
if (fansub_id_number_valid($bt_ep_id)) {
$ep_am_id = get_post_meta($bt_ep_id, 'animation', true);
if (fansub_id_number_valid($ep_am_id)) {
$ep_am = get_post($ep_am_id);
$file_name = $ep_am->post_title . ' [' . $quality . ']';
}
} else {
$ep_am_id = get_post_meta($post->ID, 'animation', true);
if (fansub_id_number_valid($ep_am_id)) {
$ep_am = get_post($ep_am_id);
$file_name = $ep_am->post_title . ' [' . $quality . ']';
}
}
}
} else {
if (!fansub_string_contain($file_name, $quality)) {
//$file_name .= ' [' . $quality . ']';
}
}
$quality_item_class = 'quality quality-' . $quality;
$server_items_html = '<li class="server-item file-name">' . $file_name . '</li>';
$server_items_html .= fansub_ph_servers_loop($servers, $quality, $post, $quality_item_class);
fansub_ph_quality_item_html($quality, $quality_item_class, $server_items_html);
?>
<?php endforeach; ?>
</ul>
</li>
</ul>
</li>
<?php
$html_items .= ob_get_clean();
}
wp_reset_postdata();
$result['html'] = $html_items;
if (!empty($html_items)) {
$result['success'] = true;
}
} else {
$result['no_post_msg'] = '<li>' . fansub_get_value_by_key($option_data, 'search_none_text') . '</li>';
}
if ((bool)$refresh) {
$query_vars['post__not_in'] = $data_post_not_in;
if ((bool)$single) {
$post_type = current($post_types);
if ('post' == $post_type) {
$query_vars['post_type'] = 'episode';
}
}
}
$query_vars['post__not_in'] = $post_not_in;
$result['query_vars'] = json_encode($query_vars);
echo json_encode($result);
die();
}
add_action('wp_ajax_fansub_kntl_search_post', 'fansub_kntl_search_post_ajax_callback');
add_action('wp_ajax_nopriv_fansub_kntl_search_post', 'fansub_kntl_search_post_ajax_callback');
function fansub_kntl_pagination_ajax_callback()
{
$result = array(
'success' => false,
'have_posts' => false,
'html' => ''
);
$query_vars = isset($_POST['query_vars']) ? $_POST['query_vars'] : array();
$query_vars = fansub_json_string_to_array($query_vars);
$paged = isset($_POST['paged']) ? $_POST['paged'] : 1;
$query_vars['paged'] = $paged;
$query = fansub_query($query_vars);
$defaults = fansub_kntl_get_option_defaults();
$option_data = fansub_kntl_get_option();
$option_data = wp_parse_args($option_data, $defaults);
$single_page = fansub_get_value_by_key($option_data, 'single_page');
if ($query->have_posts()) {
$result['have_posts'] = $query->have_posts();
$loop_html = '';
while ($query->have_posts()) {
$query->the_post();
$permalink = fansub_kntl_build_single_url($single_page, get_the_ID());
ob_start();
?>
<li <?php post_class(); ?>>
<?php
fansub_post_thumbnail(array('bfi_thumb' => false, 'lazyload' => true, 'before' => '<div class="anime-thumb">', 'after' => '</div>', 'permalink' => $permalink));
fansub_post_title_link(array('permalink' => $permalink));
fansub_entry_summary();
?>
</li>
<?php
$loop_html .= ob_get_clean();
}
wp_reset_postdata();
$result['html'] = $loop_html;
}
echo json_encode($result);
exit;
}
add_action('wp_ajax_fansub_kntl_pagination', 'fansub_kntl_pagination_ajax_callback');
add_action('wp_ajax_nopriv_fansub_kntl_pagination', 'fansub_kntl_pagination_ajax_callback');
function fansub_ph_check_post_password_ajax_callback()
{
$result = array(
'message' => 'Mật khẩu không đúng, xin vui lòng kiểm tra lại.',
'success' => false
);
$post_id = isset($_POST['post_id']) ? $_POST['post_id'] : '';
if (fansub_id_number_valid($post_id)) {
$post = get_post($post_id);
$password = isset($_POST['password']) ? $_POST['password'] : '';
if (post_password_required($post) && $post->post_password == $password) {
$result['success'] = true;
}
}
wp_send_json($result);
}
add_action('wp_ajax_fansub_ph_check_post_password', 'fansub_ph_check_post_password_ajax_callback');
add_action('wp_ajax_nopriv_fansub_ph_check_post_password', 'fansub_ph_check_post_password_ajax_callback');
function fansub_ph_get_shortlink_ajax_callback()
{
$result = array(
'success' => false,
'shortlink' => ''
);
$post_id = isset($_POST['post_id']) ? $_POST['post_id'] : '';
if (fansub_id_number_valid($post_id)) {
$shortlink = wp_get_shortlink($post_id);
$shortlink = md5($shortlink);
update_post_meta($post_id, 'shortlink', $shortlink);
$shortlink = home_url('/go/' . $shortlink);
$result['shortlink'] = $shortlink;
$result['success'] = true;
}
wp_send_json($result);
}
add_action('wp_ajax_fansub_ph_get_shortlink', 'fansub_ph_get_shortlink_ajax_callback');

View File

@ -0,0 +1,488 @@
<?php
if (!function_exists('add_filter')) {
exit;
}
define('FANSUB_PH_KEY', 'cr9Cct8&Zn5$*CxD');
class FANSUB_HRS_PageTemplater
{
/**
* A Unique Identifier
*/
protected $plugin_slug;
/**
* A reference to an instance of this class.
*/
private static $instance;
/**
* The array of templates that this plugin tracks.
*/
protected $templates;
/**
* Returns an instance of this class.
*/
public static function get_instance()
{
if (null == self::$instance) {
self::$instance = new FANSUB_HRS_PageTemplater();
}
return self::$instance;
}
/**
* Initializes the plugin by setting filters and administration functions.
*/
private function __construct()
{
$this->templates = array();
// Add a filter to the attributes metabox to inject template into the cache.
add_filter(
'page_attributes_dropdown_pages_args',
array($this, 'register_project_templates')
);
// Add a filter to the save post to inject out template into the page cache
add_filter(
'wp_insert_post_data',
array($this, 'register_project_templates')
);
// Add a filter to the template include to determine if the page has our
// template assigned and return it's path
add_filter(
'template_include',
array($this, 'view_project_template')
);
// Add your templates to this array.
$this->templates = array(
'../jwplayer.php' => 'JW Player',
);
}
/**
* Adds our template to the pages cache in order to trick WordPress
* into thinking the template file exists where it doens't really exist.
* @param $atts
* @return
*/
public function register_project_templates($atts)
{
// Create the key used for the themes cache
$cache_key = 'page_templates-' . md5(get_theme_root() . '/' . get_stylesheet());
// Retrieve the cache list.
// If it doesn't exist, or it's empty prepare an array
$templates = wp_get_theme()->get_page_templates();
if (empty($templates)) {
$templates = array();
}
// New cache, therefore remove the old one
wp_cache_delete($cache_key, 'themes');
// Now add our template to the list of templates by merging our templates
// with the existing templates array from the cache.
$templates = array_merge($templates, $this->templates);
// Add the modified cache to allow WordPress to pick it up for listing
// available templates
wp_cache_add($cache_key, $templates, 'themes', 1800);
return $atts;
}
/**
* Checks if the template is assigned to the page
* @param $template
* @return string
*/
public function view_project_template($template)
{
global $post;
if (!is_a($post, 'WP_Post')) {
return $template;
}
if (!isset($this->templates[get_post_meta(
$post->ID, '_wp_page_template', true
)])
) {
return $template;
}
$file = plugin_dir_path(__FILE__) . get_post_meta(
$post->ID, '_wp_page_template', true
);
// Just to be safe, we check if the file exist first
if (file_exists($file)) {
return $file;
} else {
echo $file;
}
return $template;
}
}
add_action('plugins_loaded', array('FANSUB_HRS_PageTemplater', 'get_instance'));
function fansub_kntl_get_post_type()
{
$value = hocwp_option_get_value('fansub_kntl', 'post_type_name');
if (empty($value)) {
$data = fansub_kntl_get_option();
$value = hocwp_get_value_by_key($data, 'post_type_name');
}
if (empty($value)) {
$value = 'post';
}
return $value;
}
function fansub_kntl_get_post_type_label_singular_name()
{
$data = fansub_kntl_get_option();
$singular_name = hocwp_get_value_by_key($data, 'post_type_label_singular_name');
if (empty($singular_name)) {
$singular_name = hocwp_get_value_by_key($data, 'post_type_label_name');
}
return $singular_name;
}
function fansub_kntl_convert_post_title_to_parts($title)
{
$post_title = str_replace(' ', '-', $title);
$title_parts = explode('-', $post_title);
return $title_parts;
}
function fansub_kntl_get_post_types()
{
return array(fansub_kntl_get_post_type(), 'episode', 'batch');
}
function fansub_kntl_get_current_animation_single()
{
$animation = get_query_var('animation');
if (!hocwp_id_number_valid($animation)) {
$animation = hocwp_get_post_by_column('post_name', $animation, 'id', array('post_type' => fansub_kntl_get_post_type()));
}
return $animation;
}
function fansub_kntl_query_new_release($args = array())
{
$transient_name = 'fansub_kntl_query_new_release';
if (false === ($query = get_transient($transient_name)) || true) {
$data_defaults = fansub_kntl_get_option();
$post_type = fansub_kntl_get_post_types();
$defaults = array(
'post_type' => $post_type,
'post_status' => 'publish'
);
unset($data_defaults['post_type']);
$defaults = shortcode_atts($defaults, $data_defaults);
$args = wp_parse_args($args, $defaults);
$query = hocwp_query($args);
$batch_ids = array();
$episode_ids = array();
$animation_ids = array();
$exclude_ids = array();
$parents_has_new_child = array();
$animations_has_new_child = array();
$animation_type = fansub_kntl_get_post_type();
$episode_type = 'episode';
$episode_child_key = 'episodes';
$batch_type = 'batch';
$batch_child_key = 'batches';
foreach ($query->posts as $post) {
if ('batch' == $post->post_type) {
$batch_ids[] = $post->ID;
} elseif ('episode' == $post->post_type) {
//$episode_ids[] = $post->ID;
} else {
$animation_ids[] = $post->ID;
}
}
foreach ($batch_ids as $id) {
$parent_id = get_post_meta($id, $episode_type, true);
$has_new_child = false;
if (hocwp_id_number_valid($parent_id)) {
$childs = get_post_meta($parent_id, $batch_child_key, true);
if (hocwp_array_has_value($childs)) {
$has_new_child = true;
$exclude_ids = array_merge($exclude_ids, $childs);
$exclude_ids = array_unique($exclude_ids);
$tmp_args = array(
'post_type' => $batch_type,
'posts_per_page' => 1,
'fields' => 'ids'
);
$tmp_query = hocwp_query_post_by_meta($episode_type, $parent_id, $tmp_args, 'numeric');
if ($tmp_query->have_posts()) {
$exclude_ids[] = $id;
$exclude_ids = array_unique($exclude_ids);
$parents_has_new_child[] = $parent_id;
$latest_id = current($tmp_query->posts);
$exclude_ids = hocwp_sanitize_array($exclude_ids);
$exclude_ids = array_unique($exclude_ids);
$exclude_ids = hocwp_remove_array_item_by_value($latest_id, $exclude_ids);
}
}
$parent_id = get_post_meta($parent_id, $animation_type, true);
if (hocwp_id_number_valid($parent_id)) {
$childs = get_post_meta($parent_id, $episode_child_key, true);
if (hocwp_array_has_value($childs)) {
$exclude_ids = array_merge($exclude_ids, $childs);
$exclude_ids = array_unique($exclude_ids);
}
}
} else {
$parent_id = get_post_meta($id, $animation_type, true);
if (hocwp_id_number_valid($parent_id)) {
$childs = get_post_meta($parent_id, $batch_child_key, true);
if (hocwp_array_has_value($childs)) {
$has_new_child = true;
$exclude_ids = array_merge($exclude_ids, $childs);
$exclude_ids = array_unique($exclude_ids);
$tmp_args = array(
'post_type' => $batch_type,
'posts_per_page' => 1,
'fields' => 'ids'
);
$tmp_query = hocwp_query_post_by_meta($animation_type, $parent_id, $tmp_args, 'numeric');
if ($tmp_query->have_posts()) {
$exclude_ids[] = $id;
$exclude_ids = array_unique($exclude_ids);
$parents_has_new_child[] = $parent_id;
$latest_id = current($tmp_query->posts);
$exclude_ids = hocwp_sanitize_array($exclude_ids);
$exclude_ids = hocwp_remove_array_item_by_value($latest_id, $exclude_ids);
}
}
}
}
}
foreach ($episode_ids as $id) {
$parent_id = get_post_meta($id, $animation_type, true);
$has_new_child = false;
if (hocwp_id_number_valid($parent_id)) {
$childs = get_post_meta($parent_id, $episode_child_key, true);
if (hocwp_array_has_value($childs)) {
$has_new_child = true;
$exclude_ids = array_merge($exclude_ids, $childs);
$exclude_ids = array_unique($exclude_ids);
$tmp_args = array(
'post_type' => $episode_type,
'posts_per_page' => 1,
'fields' => 'ids'
);
$tmp_query = hocwp_query_post_by_meta($animation_type, $parent_id, $tmp_args, 'numeric');
if ($tmp_query->have_posts()) {
$exclude_ids[] = $id;
$exclude_ids = array_unique($exclude_ids);
$parents_has_new_child[] = $parent_id;
$latest_id = current($tmp_query->posts);
$exclude_ids = hocwp_sanitize_array($exclude_ids);
$exclude_ids = hocwp_remove_array_item_by_value($latest_id, $exclude_ids);
}
}
}
}
$exclude_ids = array_merge($exclude_ids, $parents_has_new_child);
$exclude_ids = hocwp_sanitize_array($exclude_ids);
$args['post__not_in'] = $exclude_ids;
$query = hocwp_query($args);
set_transient($transient_name, $query, 3 * DAY_IN_SECONDS);
}
return $query;
}
function hocwp_horrilbesubs_get_single_page()
{
return hocwp_option_get_value('fansub_kntl', 'single_page');
}
function fansub_kntl_build_single_url($page_id, $animation_id)
{
$url = get_permalink($animation_id);
if (hocwp_id_number_valid($page_id)) {
$animation = get_post($animation_id);
$post_type = fansub_kntl_get_post_type();
if (is_a($animation, 'WP_Post') && $post_type == $animation->post_type) {
$url = get_permalink($page_id);
$permalink_struct = get_option('permalink_structure');
if (!empty($permalink_struct)) {
$url = trailingslashit($url);
$url .= trailingslashit($animation->post_name);
} else {
$url = add_query_arg(array('animation' => $animation_id), $url);
}
}
}
return $url;
}
function hocwp_ph_servers_loop($servers, $quality, $post, &$quality_item_class)
{
$server_items_html = '';
$hide_url = false;
if ('private' == $post->post_status || post_password_required($post)) {
$hide_url = true;
$class = 'server-item private-item';
if (post_password_required($post)) {
$class .= ' password-required';
}
ob_start();
?>
<li class="<?php echo $class; ?>" data-id="<?php echo $post->ID; ?>">
<a href="javascript:" class="private-link" title="Private content">
<span class="dashicons dashicons-lock"
style="color: rgb(51, 51, 51); display: inline-block; line-height: 29px; font-size: 20px;"></span>
</a>
</li>
<?php
$server_items_html .= ob_get_clean();
}
foreach ($servers as $server) : ?>
<?php
$meta_name = 'quality_' . $quality . '_' . $server;
$meta_name = hocwp_sanitize_id($meta_name);
$meta_value = get_post_meta($post->ID, $meta_name, true);
if (!empty($meta_value)) {
hocwp_add_string_with_space_before($quality_item_class, 'has-link');
}
$href = $meta_value;
if ($hide_url) {
$href = 'javascript:';
} else {
$href = hocwp_ph_encrypt_download_url($href);
}
if (!empty($meta_value)) {
$meta_value = hocwp_ph_encrypt_download_url($meta_value);
}
ob_start();
?>
<li class="server-item <?php echo $server; ?>-item">
<?php if (empty($meta_value)) : ?>
<span class="server server-<?php echo hocwp_sanitize_id($server); ?>"><?php echo $server; ?></span>
<?php else : ?>
<a href="<?php echo esc_attr($href); ?>" data-href="<?php echo esc_url($meta_value); ?>">
<span class="server server-<?php echo hocwp_sanitize_id($server); ?>"><?php echo $server; ?></span>
</a>
<?php endif; ?>
</li>
<?php
$server_items_html .= ob_get_clean();
endforeach;
return $server_items_html;
}
function hocwp_ph_quality_item_html($quality, $quality_item_class, $server_items_html)
{
?>
<li class="quality-item <?php echo $quality; ?>-item">
<span class="<?php echo $quality_item_class; ?>"><?php echo $quality; ?></span>
<ul class="list-servers">
<?php echo $server_items_html; ?>
</ul>
</li>
<?php
}
function hocwp_ph_get_qualities_and_servers($post_id = null)
{
$qualities = '';
$servers = '';
if (hocwp_id_number_valid($post_id)) {
$pq = get_post_meta($post_id, 'custom_qualities', true);
if (!empty($pq)) {
$qualities = $pq;
}
$ps = get_post_meta($post_id, 'custom_servers', true);
if (!empty($ps)) {
$servers = $ps;
}
}
$data = fansub_kntl_get_option();
if (empty($qualities)) {
$qualities = hocwp_get_value_by_key($data, 'qualities');
}
if (empty($servers)) {
$servers = hocwp_get_value_by_key($data, 'servers');
}
$qualities = hocwp_string_to_array(',', $qualities);
$qualities = array_map('trim', $qualities);
$qualities = array_filter($qualities);
$qualities = array_unique($qualities);
$servers = hocwp_string_to_array(',', $servers);
$servers = array_map('trim', $servers);
$servers = array_filter($servers);
$servers = array_unique($servers);
return array('qualities' => $qualities, 'servers' => $servers);
}
function hocwp_ph_get_auto_facebook_post_types()
{
$options = get_option('fansub_kntl');
$post_type = isset($options['fb_post_type']) ? $options['fb_post_type'] : '';
$post_type = hocwp_json_string_to_array($post_type);
$result = array();
if (hocwp_array_has_value($post_type)) {
foreach ($post_type as $value) {
if (isset($value['value'])) {
$result[] = $value['value'];
}
}
}
return $result;
}
function hocwp_ph_encrypt_download_url($url)
{
$result = home_url('/go/');
$result .= base64_encode(FANSUB_PH_KEY . '|' . $url);
return $result;
}

View File

@ -0,0 +1,909 @@
<?php
if (!function_exists('add_filter')) {
exit;
}
if (!fansub_kntl_license_valid()) {
return;
}
function fansub_kntl_post_type_and_taxonomy()
{
$data = fansub_kntl_get_option();
$post_type = fansub_get_value_by_key($data, 'post_type_name');
if (!empty($post_type) && 'post' != $post_type && 'page' != $post_type) {
$name = fansub_get_value_by_key($data, 'post_type_label_name');
if (!empty($name)) {
$singular_name = fansub_get_value_by_key($data, 'post_type_label_singular_name');
if (empty($singular_name)) {
$singular_name = $name;
}
$args = array(
'name' => $name,
'singular_name' => $singular_name,
'post_type' => $post_type,
'slug' => $post_type,
'hierarchical' => true,
'show_in_admin_bar' => true,
'supports' => array('editor', 'thumbnail', 'comments'),
'public' => true,
'has_archive' => true
);
fansub_register_post_type($args);
}
}
$args = array(
'name' => 'Batches',
'singular_name' => 'Batch',
'slug' => 'batch',
'hierarchical' => true,
'show_in_admin_bar' => true,
'public' => true,
'has_archive' => true
);
fansub_register_post_type($args);
$args = array(
'name' => 'Episodes',
'singular_name' => 'Episode',
'slug' => 'episode',
'hierarchical' => true,
'show_in_admin_bar' => true,
'public' => true,
'has_archive' => true
);
fansub_register_post_type($args);
$args = array(
'name' => 'Videos',
'singular_name' => 'Video',
'slug' => 'video',
'hierarchical' => true,
'show_in_admin_bar' => true,
'public' => true,
'supports' => array('thumbnail', 'editor'),
'has_archive' => true
);
fansub_register_post_type($args);
}
add_action('fansub_post_type_and_taxonomy', 'fansub_kntl_post_type_and_taxonomy', 0);
function fansub_kntl_redirect_after_comment($location)
{
global $wpdb;
if (is_page()) {
$single_page = fansub_option_get_value('fansub_kntl', 'single_page');
if (get_the_ID() == $single_page) {
$location = $_SERVER["HTTP_REFERER"] . "#comment-" . $wpdb->insert_id;
}
}
return $location;
}
add_filter('comment_post_redirect', 'fansub_kntl_redirect_after_comment', 99);
function fansub_kntl_custom_permalink($permalink, $post, $leavename)
{
$post_type = fansub_kntl_get_post_type();
if ($post_type == $post->post_type) {
$page_id = fansub_option_get_value('fansub_kntl', 'single_page');
if (fansub_id_number_valid($page_id)) {
remove_filter('post_link', 'fansub_kntl_custom_permalink', 99);
$new_link = fansub_kntl_build_single_url($page_id, $post->ID);
add_filter('post_link', 'fansub_kntl_custom_permalink', 99, 3);
$permalink = $new_link;
}
} else {
if ('batch' == $post->post_type || 'episode' == $post->post_type || 'video' == $post->post_type) {
$page_id = fansub_option_get_value('fansub_kntl', 'single_page');
if (fansub_id_number_valid($page_id)) {
remove_filter('post_link', 'fansub_kntl_custom_permalink', 99);
$post_id = get_post_meta($post->ID, 'animation', true);
if (fansub_array_has_value($post_id)) {
$post_id = array_shift($post_id);
}
$new_link = fansub_kntl_build_single_url($page_id, $post_id);
add_filter('post_link', 'fansub_kntl_custom_permalink', 99, 3);
$permalink = $new_link;
}
}
}
return $permalink;
}
add_filter('post_link', 'fansub_kntl_custom_permalink', 99, 3);
function fansub_kntl_post_type_link($url, $post)
{
$post_type = fansub_kntl_get_post_type();
if ($post_type == $post->post_type || 'batch' == $post->post_type || 'episode' == $post->post_type || 'video' == $post->post_type) {
$page_id = fansub_option_get_value('fansub_kntl', 'single_page');
if (fansub_id_number_valid($page_id)) {
remove_filter('post_type_link', 'fansub_kntl_post_type_link', 10);
$post_id = $post->ID;
if ($post_type != $post->post_type) {
$post_id = get_post_meta($post->ID, 'animation', true);
}
if (fansub_array_has_value($post_id)) {
$post_id = array_shift($post_id);
}
$new_link = fansub_kntl_build_single_url($page_id, $post_id);
add_filter('post_type_link', 'fansub_kntl_post_type_link', 10, 2);
$url = $new_link;
}
}
return $url;
}
add_filter('post_type_link', 'fansub_kntl_post_type_link', 10, 2);
function fansub_kntl_use_chosen_select()
{
return true;
}
add_filter('fansub_use_chosen_select', 'fansub_kntl_use_chosen_select');
function fansub_kntl_check_before_post_published($post_id)
{
global $pagenow;
if (!fansub_can_save_post($post_id) || !is_numeric($post_id)) {
return;
}
$post_new = false;
if ('post-new.php' == $pagenow) {
$post_new = true;
}
$post_type = fansub_get_current_post_type();
$prevent_publish = false;
switch ($post_type) {
case 'episode':
$animation = get_post_meta($post_id, 'animation', true);
$animation = absint($animation);
if ($animation < 1 && !$post_new) {
$prevent_publish = true;
set_transient('fansub_kntl_episode_missing_animation', 1);
}
break;
case 'batch':
$episode = get_post_meta($post_id, 'episode', true);
$episode = absint($episode);
$animation = get_post_meta($post_id, 'animation', true);
$animation = absint($animation);
if ($episode < 1 && !$post_new && $animation < 1) {
$prevent_publish = true;
set_transient('fansub_kntl_batch_missing_episode', 1);
}
break;
}
if ($prevent_publish && !$post_new) {
remove_action('save_post', 'fansub_kntl_check_before_post_published');
if ('trash' != get_post_status($post_id)) {
wp_update_post(array('ID' => $post_id, 'post_status' => 'draft'));
}
} else {
delete_transient('fansub_kntl_query_new_release');
}
}
add_action('save_post', 'fansub_kntl_check_before_post_published');
function fansub_kntl_redirect_post_location($location, $post_id)
{
if (isset($_POST['publish'])) {
$status = get_post_status($post_id);
if ($status == 'draft') {
$location = add_query_arg('message', 10, $location);
}
}
return $location;
}
add_filter('redirect_post_location', 'fansub_kntl_redirect_post_location', 10, 2);
function fansub_kntl_admin_notices()
{
global $pagenow;
if ('post-new.php' == $pagenow) {
return;
}
if (false !== get_transient('fansub_kntl_batch_missing_episode')) {
$args = array(
'title' => 'Error',
'text' => 'Please select episode for batch.',
'error' => true
);
fansub_admin_notice($args);
delete_transient('fansub_kntl_batch_missing_episode');
} elseif (false !== get_transient('fansub_kntl_episode_missing_animation')) {
$args = array(
'title' => 'Error',
'text' => 'Please select ' . fansub_kntl_get_post_type() . ' for episode.',
'error' => true
);
$post_type = fansub_get_current_post_type();
if ('post.php' == $pagenow && 'episode' == $post_type) {
fansub_admin_notice($args);
}
delete_transient('fansub_kntl_episode_missing_animation');
}
}
add_action('admin_notices', 'fansub_kntl_admin_notices');
function fansub_kntl_query_vars($vars)
{
$vars[] = 'animation';
return $vars;
}
add_filter('query_vars', 'fansub_kntl_query_vars');
function fansub_kntl_rewrite_rules($rules)
{
$new_rule = array('shows/([^/]+)/?$' => 'index.php?pagename=shows&animation=$matches[1]', 'top');
$rules = $new_rule + $rules;
return $rules;
}
add_filter('rewrite_rules_array', 'fansub_kntl_rewrite_rules');
function fansub_kntl_template_redirect()
{
if (is_page()) {
$permalink_struct = get_option('permalink_structure');
if (empty($permalink_struct)) {
return;
}
$option_data = fansub_kntl_get_option();
$single_page = fansub_get_value_by_key($option_data, 'single_page');
$show_page = get_post($single_page);
$post_id = get_query_var('page_id');
$pagename = get_query_var('pagename');
if ((fansub_id_number_valid($post_id) && $post_id == $single_page) || ($pagename == $show_page->post_name)) {
$query_var = get_query_var('animation');
if (!fansub_id_number_valid($query_var)) {
return;
}
$animation = fansub_kntl_get_current_animation_single();
if (fansub_id_number_valid($animation)) {
$animation = get_post($animation);
if (is_a($animation, 'WP_Post')) {
$page = get_post($post_id);
if (!is_a($page, 'WP_Post')) {
$page = get_page_by_path($pagename);
}
if ('page' == $page->post_type) {
$url = trailingslashit(get_permalink($page));
$url .= trailingslashit(trim(sanitize_title_for_query($animation->post_name)));
wp_redirect($url);
exit;
}
}
}
}
}
}
add_action('template_redirect', 'fansub_kntl_template_redirect');
function fansub_kntl_the_title($title, $post_id)
{
if (is_page()) {
$option_data = fansub_kntl_get_option();
$single_page = fansub_get_value_by_key($option_data, 'single_page');
if ($post_id == $single_page) {
$animation = fansub_kntl_get_current_animation_single();
if (fansub_id_number_valid($animation)) {
$animation = get_post($animation);
if (is_a($animation, 'WP_Post')) {
$page = get_post($post_id);
if ('page' == $page->post_type) {
$title = $animation->post_title;
if ('private' == $animation->post_status) {
$title = 'Private: ' . $title;
} elseif (post_password_required($animation)) {
$title = 'Protected: ' . $title;
}
}
}
}
} else {
$page = get_post($post_id);
if (is_a($page, 'WP_Post')) {
if (has_shortcode($page->post_content, 'fansub_release')) {
$title = '';
}
}
}
}
return $title;
}
add_filter('the_title', 'fansub_kntl_the_title', 10, 2);
function fansub_kntl_yoast_seo_title($title)
{
if (is_page()) {
$post_id = get_the_ID();
$option_data = fansub_kntl_get_option();
$single_page = fansub_get_value_by_key($option_data, 'single_page');
if ($post_id == $single_page) {
$animation = fansub_kntl_get_current_animation_single();
if (fansub_id_number_valid($animation)) {
$animation = get_post($animation);
if (is_a($animation, 'WP_Post')) {
$page = get_post($post_id);
if ('page' == $page->post_type) {
$title = $animation->post_title;
}
}
}
} else {
$page = get_post($post_id);
if (is_a($page, 'WP_Post')) {
if (has_shortcode($page->post_content, 'fansub_release')) {
$title = '';
}
}
}
}
return $title;
}
add_filter('wpseo_title', 'fansub_kntl_yoast_seo_title');
function fansub_kntl_custom_body_class($classes)
{
if (is_page()) {
$option_data = fansub_kntl_get_option();
$single_page = fansub_get_value_by_key($option_data, 'single_page');
if (get_the_ID() == $single_page) {
$classes[] = 'single-animation';
}
}
}
add_filter('body_class', 'fansub_kntl_custom_body_class');
function fansub_kntl_change_wp_title($title, $sep, $seplocation)
{
if (is_page()) {
$option_data = fansub_kntl_get_option();
$single_page = fansub_get_value_by_key($option_data, 'single_page');
if (get_the_ID() == $single_page) {
$animation = fansub_kntl_get_current_animation_single();
if (fansub_id_number_valid($animation)) {
$animation = get_post($animation);
if (is_a($animation, 'WP_Post')) {
$title = $animation->post_title;
if (!empty($sep)) {
if ('right' == $seplocation) {
$title .= ' ' . $sep . ' ' . get_bloginfo('name');
} else {
$title = get_bloginfo('name') . ' ' . $sep . ' ' . $title;
}
}
}
}
}
}
return $title;
}
add_filter('wp_title', 'fansub_kntl_change_wp_title', 99, 3);
function fansub_kntl_option_saved()
{
delete_transient('fansub_kntl_query_new_release');
}
add_action('fansub_option_saved', 'fansub_kntl_option_saved');
function fansub_kntl_wpseo_opengraph_url($content)
{
if (is_page()) {
$option_data = fansub_kntl_get_option();
$single_page = fansub_get_value_by_key($option_data, 'single_page');
if (get_the_ID() == $single_page) {
$animation = fansub_kntl_get_current_animation_single();
if (fansub_id_number_valid($animation)) {
$animation = get_post($animation);
if (is_a($animation, 'WP_Post')) {
$content = fansub_kntl_build_single_url(get_the_ID(), $animation->ID);
}
}
}
}
return $content;
}
add_filter('wpseo_opengraph_url', 'fansub_kntl_wpseo_opengraph_url', 99);
add_filter('wpseo_canonical', 'fansub_kntl_wpseo_opengraph_url', 99);
function fansub_kntl_wpseo_opengraph_desc($content)
{
if (is_page()) {
$option_data = fansub_kntl_get_option();
$single_page = fansub_get_value_by_key($option_data, 'single_page');
if (get_the_ID() == $single_page) {
$animation = fansub_kntl_get_current_animation_single();
if (fansub_id_number_valid($animation)) {
$animation = get_post($animation);
if (is_a($animation, 'WP_Post')) {
$content = $animation->post_content;
$content = wp_strip_all_tags($content);
$content = fansub_substr($content, 165);
}
}
}
}
return $content;
}
add_filter('wpseo_opengraph_desc', 'fansub_kntl_wpseo_opengraph_desc', 99);
function fansub_kntl_wpseo_opengraph_title($content)
{
if (is_page()) {
$option_data = fansub_kntl_get_option();
$single_page = fansub_get_value_by_key($option_data, 'single_page');
if (get_the_ID() == $single_page) {
$animation = fansub_kntl_get_current_animation_single();
if (fansub_id_number_valid($animation)) {
$animation = get_post($animation);
if (is_a($animation, 'WP_Post')) {
$content = $animation->post_title . ' - ' . get_bloginfo('name');
}
}
}
}
return $content;
}
add_filter('wpseo_opengraph_title', 'fansub_kntl_wpseo_opengraph_title', 99);
add_filter('wpseo_twitter_title', 'fansub_kntl_wpseo_opengraph_title', 99);
function fansub_kntl_wpseo_opengraph_image($content)
{
if (is_page()) {
$option_data = fansub_kntl_get_option();
$single_page = fansub_get_value_by_key($option_data, 'single_page');
if (get_the_ID() == $single_page) {
$animation = fansub_kntl_get_current_animation_single();
if (fansub_id_number_valid($animation)) {
$animation = get_post($animation);
if (is_a($animation, 'WP_Post')) {
$content = fansub_get_post_thumbnail_url($animation->ID);
}
}
}
}
return $content;
}
add_filter('wpseo_opengraph_image', 'fansub_kntl_wpseo_opengraph_image', 99);
function fansub_kntl_amt_metadata_head($metadata_arr)
{
if (is_page()) {
$option_data = fansub_kntl_get_option();
$single_page = fansub_get_value_by_key($option_data, 'single_page');
if (get_the_ID() == $single_page) {
$animation = fansub_kntl_get_current_animation_single();
if (fansub_id_number_valid($animation)) {
$animation = get_post($animation);
if (is_a($animation, 'WP_Post')) {
if (fansub_array_has_value($metadata_arr)) {
$tmp_metas = array();
$has_og_image = false;
$has_og_description = false;
foreach ($metadata_arr as $metadata) {
$property = fansub_get_tag_attr('meta', 'property', $metadata);
if (empty($property)) {
$property = fansub_get_tag_attr('meta', 'name', $metadata);
}
switch ($property) {
case 'og:url':
$url = fansub_kntl_build_single_url(get_the_ID(), $animation->ID);
$metadata = fansub_change_tag_attribute($metadata, 'content', $url);
break;
case 'og:updated_time':
$metadata = fansub_change_tag_attribute($metadata, 'content', get_post_modified_time('c', true, $animation));
break;
case 'article:published_time':
$metadata = fansub_change_tag_attribute($metadata, 'content', get_post_time('c', true, $animation));
break;
case 'article:modified_time':
$metadata = fansub_change_tag_attribute($metadata, 'content', get_post_modified_time('c', true, $animation));
break;
case 'og:image':
$has_og_image = true;
$metadata = fansub_change_tag_attribute($metadata, 'content', fansub_get_post_thumbnail_url($animation->ID));
break;
case 'og:description':
$has_og_description = true;
$content = $animation->post_content;
$content = wp_strip_all_tags($content);
$content = fansub_substr($content, 165);
$metadata = fansub_change_tag_attribute($metadata, 'content', $content);
break;
}
$tmp_metas[] = $metadata;
}
if (!$has_og_image) {
$tmp_metas[] = '<meta property="og:image" content="' . fansub_get_post_thumbnail_url($animation->ID) . '" />';
}
if (!$has_og_description) {
$content = $animation->post_content;
$content = wp_strip_all_tags($content);
$content = fansub_substr($content, 165);
$tmp_metas[] = '<meta property="og:description" content="' . $content . '" />';
}
$metadata_arr = $tmp_metas;
}
}
}
}
}
return $metadata_arr;
}
add_filter('amt_metadata_head', 'fansub_kntl_amt_metadata_head', 99);
function fansub_kntl_single_shortlink($shortlink, $id, $context, $allow_slugs)
{
if (is_page()) {
$option_data = fansub_kntl_get_option();
$single_page = fansub_get_value_by_key($option_data, 'single_page');
if (get_the_ID() == $single_page) {
$animation = fansub_kntl_get_current_animation_single();
if (fansub_id_number_valid($animation)) {
$animation = get_post($animation);
if (is_a($animation, 'WP_Post')) {
remove_filter('pre_get_shortlink', 'fansub_kntl_single_shortlink', 99);
$shortlink = wp_get_shortlink($id);
add_filter('pre_get_shortlink', 'fansub_kntl_single_shortlink', 99, 4);
$shortlink = add_query_arg(array('animation' => $animation->ID), $shortlink);
}
}
}
}
return $shortlink;
}
add_filter('pre_get_shortlink', 'fansub_kntl_single_shortlink', 99, 4);
remove_action('wp_head', 'rel_canonical');
add_action('wp_head', 'fansub_rel_canonical');
function fansub_kntl_change_head_rel_canonical($link, $id)
{
if (is_page()) {
$option_data = fansub_kntl_get_option();
$single_page = fansub_get_value_by_key($option_data, 'single_page');
if ($id == $single_page) {
$animation = fansub_kntl_get_current_animation_single();
if (fansub_id_number_valid($animation)) {
$animation = get_post($animation);
if (is_a($animation, 'WP_Post')) {
$link = fansub_kntl_build_single_url($id, $animation->ID);
}
}
}
}
return $link;
}
add_filter('fansub_head_rel_canonical', 'fansub_kntl_change_head_rel_canonical', 99, 2);
function fansub_kntl_get_edit_post_link($link, $post_id, $context)
{
if (is_page()) {
$page = get_post($post_id);
if ('shows' == $page->post_name) {
$qa = fansub_kntl_get_current_animation_single();
$animate = get_post($qa);
if (is_a($animate, 'WP_Post')) {
$link = admin_url('post.php?post=' . $animate->ID . '&action=edit');
}
}
}
return $link;
}
add_filter('get_edit_post_link', 'fansub_kntl_get_edit_post_link', 99, 3);
function fansub_kntl_custom_scripts()
{
wp_register_script('scrollstop', FANSUB_KNTL_URL . '/lib/lazyload/jquery.scrollstop.min.js', array('jquery'),
false, true);
wp_enqueue_script('lazyload', FANSUB_KNTL_URL . '/lib/lazyload/jquery.lazyload.min.js', array(
'jquery',
'scrollstop'
),
false, true);
wp_enqueue_style('fancybox-style', FANSUB_KNTL_URL . '/lib/fancybox/jquery.fancybox.css');
wp_enqueue_script('fancybox', FANSUB_KNTL_URL . '/lib/fancybox/jquery.fancybox.pack.js', array('jquery'), false, true);
wp_enqueue_style('bxslider-style', FANSUB_KNTL_URL . '/lib/bxslider/jquery.bxslider.css');
wp_enqueue_script('bxslider', FANSUB_KNTL_URL . '/lib/bxslider/jquery.bxslider.min.js', array('jquery'), false, true);
global $wp_scripts;
$ui = $wp_scripts->query('jquery-ui-core');
$protocol = is_ssl() ? 'https' : 'http';
$url = "$protocol://ajax.googleapis.com/ajax/libs/jqueryui/{$ui->ver}/themes/smoothness/jquery-ui.min.css";
wp_enqueue_style('jquery-ui-style', $url);
wp_enqueue_script('jquery-ui-autocomplete');
wp_enqueue_style('dashicons');
}
add_action('wp_enqueue_scripts', 'fansub_kntl_custom_scripts');
function fansub_kntl_custom_redirect_single_animation()
{
if (is_preview()) {
return;
}
$post_type = fansub_kntl_get_post_type();
if (is_singular($post_type) || is_singular('batch') || is_singular('episode') || is_singular('video')) {
global $post;
$single_page = fansub_option_get_value('fansub_kntl', 'single_page');
if (fansub_id_number_valid($single_page)) {
$post_id = $post->ID;
if ($post_type != $post->post_type) {
$post_id = get_post_meta($post_id, 'animation');
if (fansub_array_has_value($post_id)) {
$post_id = array_shift($post_id);
}
}
$permalink = fansub_kntl_build_single_url($single_page, $post_id);
wp_redirect($permalink);
exit;
}
}
}
add_action('wp', 'fansub_kntl_custom_redirect_single_animation');
function fansub_kntl_custom_admin_scripts()
{
wp_enqueue_media();
wp_enqueue_script('zeroclipboard', FANSUB_KNTL_URL . '/lib/zeroclipboard/ZeroClipboard.min.js', array('jquery'), false, true);
}
add_action('admin_enqueue_scripts', 'fansub_kntl_custom_admin_scripts');
function fansub_kntl_custom_posts_columns($columns)
{
global $post_type;
switch ($post_type) {
case 'batch':
$columns['animation'] = __('Animation', 'fansub-horriblesubs');
$columns['episode'] = __('Episode', 'fansub-horriblesubs');
break;
case 'episode':
$columns['animation'] = __('Animation', 'fansub-horriblesubs');
break;
}
return $columns;
}
add_filter('manage_posts_columns', 'fansub_kntl_custom_posts_columns', 99);
function fansub_kntl_custom_posts_custom_column($column, $post_id)
{
switch ($column) {
case 'animation':
$animation = get_post_meta($post_id, 'animation', true);
if (fansub_id_number_valid($animation)) {
$animation = get_post($animation);
if (is_a($animation, 'WP_Post')) {
echo $animation->post_title;
}
}
break;
case 'episode':
$episode = get_post_meta($post_id, 'episode', true);
if (fansub_id_number_valid($episode)) {
$episode = get_post($episode);
if (is_a($episode, 'WP_Post')) {
echo $episode->post_title;
}
}
break;
}
}
add_action('manage_batch_posts_custom_column', 'fansub_kntl_custom_posts_custom_column', 10, 2);
add_action('manage_episode_posts_custom_column', 'fansub_kntl_custom_posts_custom_column', 10, 2);
function fansub_ph_add_query_vars($vars)
{
$vars[] = 'go';
return $vars;
}
add_filter('query_vars', 'fansub_ph_add_query_vars');
function fansub_ph_init()
{
add_rewrite_endpoint('go', EP_ALL);
//add_rewrite_rule('^go/([^/]*)/?)', 'index.php?go=$matches[1]', 'top');
}
add_action('init', 'fansub_ph_init', 0);
function fansub_ph_custom_template_redirect()
{
$go = get_query_var('go');
if (!empty($go)) {
$go = base64_decode($go);
$parts = explode('|', $go);
if (is_array($parts) && count($parts) == 2) {
$url = $parts[1];
if (filter_var($url, FILTER_VALIDATE_URL)) {
wp_redirect($url);
exit;
}
}
} else {
return;
}
if (empty($go)) {
$go = fansub_get_method_value('link', 'get');
$parts = explode('p=', $go);
if (is_array($parts) && count($parts) == 2) {
$post_id = $parts[1];
if (fansub_id_number_valid($post_id)) {
$post = get_post($post_id);
if (is_a($post, 'WP_Post')) {
$click_count = get_post_meta($post_id, 'click_count', true);
$click_count = absint($click_count);
$click_count++;
update_post_meta($post_id, 'click_count', $click_count);
}
}
}
}
if (fansub_id_number_valid($go)) {
$post = get_post($go);
if (is_a($post, 'WP_Post')) {
$click_count = get_post_meta($go, 'click_count', true);
$click_count = absint($click_count);
$click_count++;
update_post_meta($go, 'click_count', $click_count);
wp_redirect(wp_get_shortlink($post));
exit;
}
} elseif (filter_var($go, FILTER_VALIDATE_URL)) {
wp_redirect($go);
exit;
} elseif (!empty($go)) {
$query = fansub_get_post_by_meta('shortlink', $go);
if ($query->have_posts()) {
$post = array_shift($query->posts);
$post_id = $post->ID;
$click_count = get_post_meta($post_id, 'click_count', true);
$click_count = absint($click_count);
$click_count++;
update_post_meta($post_id, 'click_count', $click_count);
wp_redirect(wp_get_shortlink($post));
exit;
}
}
}
add_action('wp', 'fansub_ph_custom_template_redirect');
function fansub_ph_on_admin_init()
{
global $pagenow;
if ('admin.php' == $pagenow) {
$page = fansub_get_method_value('page', 'get');
if ('fansub_kntl' == $page) {
$options = get_option('fansub_kntl');
$fb_app_id = fansub_get_value_by_key($options, 'fb_app_id');
if (!empty($fb_app_id)) {
$fb_code = fansub_get_value_by_key($options, 'fb_code');
if (empty($fb_code)) {
$fb_app_secret = fansub_get_value_by_key($options, 'fb_app_secret');
$fb_redirect_uri = fansub_get_value_by_key($options, 'fb_redirect_uri');
if (empty($fb_redirect_uri)) {
$protocol = isset($_SERVER['HTTPS']) ? 'https' : 'http';
$protocol .= '://';
$fb_redirect_uri = $protocol;
if (isset($_SERVER['HTTP_HOST'])) {
$fb_redirect_uri .= $_SERVER['HTTP_HOST'];
if (isset($_SERVER['REQUEST_URI'])) {
$fb_redirect_uri .= $_SERVER['REQUEST_URI'];
}
}
}
$url = 'https://www.facebook.com/dialog/oauth';
$params = array(
'client_id' => $fb_app_id,
'redirect_uri' => $fb_redirect_uri,
'scope' => 'manage_pages,publish_actions'
);
$url = add_query_arg($params, $url);
}
}
}
}
}
add_action('admin_init', 'fansub_ph_on_admin_init');
function fansub_ph_auto_post_facebook($post_id)
{
if (!fansub_can_save_post($post_id)) {
return;
}
$post = get_post($post_id);
$new_status = $post->post_status;
$post_type = fansub_ph_get_auto_facebook_post_types();
if (in_array($post->post_type, $post_type) && 'publish' == $new_status && isset($_POST['auto_facebook']) && 1 == $_POST['auto_facebook']) {
$options = get_option('fansub_kntl');
$fb_app_id = fansub_get_value_by_key($options, 'fb_app_id');
if (!empty($fb_app_id)) {
$fb_app_secret = fansub_get_value_by_key($options, 'fb_app_secret');
if (!empty($fb_app_secret)) {
$fb_access_token = fansub_get_value_by_key($options, 'fb_access_token');
if (!empty($fb_access_token)) {
$auto_facebook = get_post_meta($post_id, 'auto_facebook', true);
if (1 != $auto_facebook) {
require_once(FANSUB_KNTL_PATH . '/lib/Facebook/autoload.php');
$fb = new Facebook\Facebook([
'app_id' => $fb_app_id,
'app_secret' => $fb_app_secret,
'default_graph_version' => 'v2.9',
]);
$linkData = [
'link' => esc_url(get_permalink($post)),
'message' => $post->post_title,
'privacy' => json_encode(array('value' => 'EVERYONE'))
];
$response = null;
try {
$response = $fb->post('/me/feed', $linkData, $fb_access_token);
} catch (Facebook\Exceptions\FacebookResponseException $e) {
} catch (Facebook\Exceptions\FacebookSDKException $e) {
}
if ($response) {
update_post_meta($post_id, 'auto_facebook', 1);
}
}
}
}
}
}
}
add_action('save_post', 'fansub_ph_auto_post_facebook', 99);

View File

@ -0,0 +1,277 @@
<?php
if (!function_exists('add_filter')) exit;
if (!fansub_kntl_license_valid()) {
return;
}
global $pagenow;
if ('post.php' == $pagenow || 'post-new.php' == $pagenow) {
global $post_ID;
$post_type = fansub_get_current_post_type();
$post = null;
if ('post-new.php' == $pagenow) {
if (!function_exists('get_default_post_to_edit')) {
require_once ABSPATH . 'wp-admin/includes/post.php';
}
$post = get_default_post_to_edit($post_type);
}
$post_types = array('batch', 'episode', 'video');
fansub_meta_box_post_attribute($post_types);
$meta = new FANSUB_Meta('post');
$meta->add_post_type('video');
$meta->set_id('fansub_video_information');
$meta->set_title('Video Information');
$meta->set_use_media_upload(true);
$meta->add_field(array('id' => 'video_url', 'label' => 'Video URL:'));
//$meta->init();
$meta = new FANSUB_Meta('post');
$meta->add_post_type('episode');
$meta->add_post_type('batch');
$meta->set_id('post_information');
$meta->set_title('Extra Information');
$meta->set_use_media_upload(true);
$meta->add_field(array('id' => 'custom_qualities', 'label' => 'Custom qualities:'));
$meta->add_field(array('id' => 'custom_servers', 'label' => 'Custom servers:'));
$value = '';
if ('post.php' == $pagenow) {
$post_id = fansub_get_method_value('post', 'get');
if (fansub_id_number_valid($post_id)) {
$shortlink = get_post_meta($post_id, 'shortlink', true);
if (empty($shortlink)) {
$shortlink = md5(wp_get_shortlink($post_id));
update_post_meta($post_id, 'shortlink', $shortlink);
}
if (!empty($shortlink)) {
$shortlink = home_url('/go/' . $shortlink);
$value = $shortlink;
}
}
}
$args = array(
'id' => 'go_shortlink',
'readonly' => true,
'value' => $value,
'attributes' => array(
'readonly' => 'readonly',
'autocomplete' => 'off'
),
'label' => 'Shortlink:'
);
$meta->add_field($args);
$meta->init();
add_action('fansub_post_meta_box_field', 'fansub_kntl_meta_box_field');
add_action('save_post', 'fansub_kntl_save_post_meta');
$post_id = null;
if ('post.php' == $pagenow) {
$post_id = fansub_get_method_value('post', 'get');
}
$qs = fansub_ph_get_qualities_and_servers($post_id);
$qualities = $qs['qualities'];
$servers = $qs['servers'];
foreach ($qualities as $quality) {
$meta_id = 'quality_' . $quality;
$meta_id = fansub_sanitize_id($meta_id);
$post_meta = new FANSUB_Meta('post');
$post_meta->set_id($meta_id);
$field_name = $meta_id . '_file_name';
$post_meta->add_field(array('name' => $field_name, 'label' => 'File Name [' . $quality . ']'));
foreach ($servers as $server) {
$field_name = $meta_id . '_' . $server;
$field_name = fansub_sanitize_id($field_name);
$post_meta->add_field(array('name' => $field_name, 'label' => fansub_uppercase_first_char($server)));
}
$post_meta->set_title($quality);
$post_meta->set_post_types(array('episode', 'batch'));
$post_meta->init();
}
}
function fansub_kntl_meta_box_field($meta)
{
if (!is_object($meta)) {
return;
}
global $post;
$meta_id = $post->post_type . '_attributes';
$meta_id = fansub_sanitize_id($meta_id);
$animation_type = fansub_kntl_get_post_type();
if ($meta->get_id() == $meta_id) {
$post_type = $post->post_type;
if ('episode' == $post_type || 'video' == $post_type) {
$query = fansub_query(array('post_type' => fansub_kntl_get_post_type(), 'posts_per_page' => -1));
$all_option = '<option value=""></option>';
$selected = get_post_meta($post->ID, $animation_type, true);
foreach ($query->posts as $qpost) {
$all_option .= fansub_field_get_option(array('value' => $qpost->ID, 'text' => $qpost->post_title, 'selected' => $selected));
}
$args = array(
'id' => $animation_type,
'name' => $animation_type,
'all_option' => $all_option,
'value' => $selected,
'class' => 'widefat',
'label' => fansub_uppercase_first_char_only(fansub_kntl_get_post_type_label_singular_name()) . ':',
'placeholder' => __('Choose parent post', 'fansub')
);
fansub_field_select_chosen($args);
if ('video' == $post_type) {
$only_member = get_post_meta($post->ID, 'only_member', true);
$args = array(
'id' => 'only_member',
'name' => 'only_member',
'value' => $only_member,
'label' => __('Disable for guest?', 'fansub')
);
fansub_field_input_checkbox($args);
}
} elseif ('batch' == $post_type) {
$query = fansub_query(array('post_type' => fansub_kntl_get_post_type(), 'posts_per_page' => -1));
$all_option = '<option value=""></option>';
$selected = get_post_meta($post->ID, $animation_type, true);
foreach ($query->posts as $qpost) {
$all_option .= fansub_field_get_option(array('value' => $qpost->ID, 'text' => $qpost->post_title, 'selected' => $selected));
}
$args = array(
'id' => $animation_type,
'name' => $animation_type,
'all_option' => $all_option,
'value' => $selected,
'class' => 'widefat',
'label' => fansub_uppercase_first_char_only(fansub_kntl_get_post_type_label_singular_name()) . ':',
'placeholder' => __('Choose parent post', 'fansub')
);
fansub_field_select_chosen($args);
$query = fansub_query(array('post_type' => 'episode', 'posts_per_page' => -1));
$all_option = '<option value=""></option>';
$selected = get_post_meta($post->ID, 'episode', true);
foreach ($query->posts as $qpost) {
$all_option .= fansub_field_get_option(array('value' => $qpost->ID, 'text' => $qpost->post_title, 'selected' => $selected));
}
$args = array(
'id' => 'episode',
'name' => 'episode',
'all_option' => $all_option,
'value' => $selected,
'class' => 'widefat',
'label' => 'Episode:',
'placeholder' => __('Choose parent post', 'fansub')
);
fansub_field_select_chosen($args);
$value = get_post_meta($post->ID, 'suffix', true);
$args = array(
'id' => 'suffix',
'name' => 'suffix',
'value' => $value,
'label' => 'Suffix:'
);
fansub_field_input($args);
}
$post_types = fansub_ph_get_auto_facebook_post_types();
if (in_array($post->post_type, $post_types)) {
$value = get_post_meta($post->ID, 'auto_facebook', true);
$args = array(
'id' => 'auto_facebook',
'name' => 'auto_facebook',
'value' => $value,
'label' => 'Auto publish to Facebook?',
'default' => 1
);
fansub_field_input_checkbox($args);
}
}
}
function fansub_kntl_save_post_meta($post_id)
{
if (!fansub_can_save_post($post_id)) {
return;
}
$animation_type = fansub_kntl_get_post_type();
$post = get_post($post_id);
$post_title = $post->post_title;
$title_parts = fansub_kntl_convert_post_title_to_parts($post_title);
array_shift($title_parts);
$title_parts = array_map('trim', $title_parts);
$post_type = fansub_get_current_post_type();
$suffix = isset($_POST['suffix']) ? $_POST['suffix'] : '';
update_post_meta($post_id, 'suffix', $suffix);
if ('episode' == $post_type || 'video' == $post_type) {
$animation = isset($_POST[$animation_type]) ? $_POST[$animation_type] : '';
update_post_meta($post_id, $animation_type, $animation);
if (is_numeric($animation) && $animation > 0) {
$episodes = get_post_meta($animation, 'episodes', true);
$episodes = fansub_sanitize_array($episodes);
if (!in_array($post_id, $episodes)) {
$episodes[] = $post_id;
}
update_post_meta($animation, 'episodes', $episodes);
}
$title_count = array_pop($title_parts);
update_post_meta($post_id, 'episode', $title_count);
if ('video' == $post_type) {
$only_member = fansub_checkbox_post_data_value($_POST, 'only_member');
update_post_meta($post_id, 'only_member', $only_member);
}
} elseif ('batch' == $post_type) {
$episode = isset($_POST['episode']) ? $_POST['episode'] : '';
update_post_meta($post_id, 'episode', $episode);
if (fansub_id_number_valid($episode)) {
$batches = get_post_meta($episode, 'batches', true);
$batches = fansub_sanitize_array($batches);
if (!in_array($post_id, $batches)) {
$batches[] = $post_id;
}
update_post_meta($episode, 'batches', $batches);
}
$animation = isset($_POST[$animation_type]) ? $_POST[$animation_type] : '';
update_post_meta($post_id, $animation_type, $animation);
if (fansub_id_number_valid($animation)) {
$batches = get_post_meta($animation, 'batches', true);
$batches = fansub_sanitize_array($batches);
if (!in_array($post_id, $batches)) {
$batches[] = $post_id;
}
update_post_meta($animation, 'batches', $batches);
}
$title_count = array_pop($title_parts);
$title_count = array_pop($title_parts);
update_post_meta($post_id, 'batch', $title_count);
}
$qs = fansub_ph_get_qualities_and_servers($post_id);
$qualities = $qs['qualities'];
$servers = $qs['servers'];
foreach ($qualities as $quality) {
$meta_id = 'quality_' . $quality;
$meta_id = fansub_sanitize_id($meta_id);
$field_name = $meta_id . '_file_name';
if (isset($_POST[$field_name])) {
update_post_meta($post_id, $field_name, $_POST[$field_name]);
}
foreach ($servers as $server) {
$field_name = $meta_id . '_' . $server;
$field_name = fansub_sanitize_id($field_name);
if (isset($_POST[$field_name])) {
update_post_meta($post_id, $field_name . '_encrypted', $_POST[$field_name]);
}
}
}
}

View File

@ -0,0 +1,17 @@
<?php
if(!function_exists('add_filter')) exit;
function fansub_kntl_compress_path($paths) {
$paths[] = FANSUB_KNTL_PATH;
return $paths;
}
add_filter('fansub_compress_paths', 'fansub_kntl_compress_path');
function fansub_kntl_license_data($data) {
$data = array(
'hashed' => '$P$BjfKqVglqWgOhH8AGH8YInbWU8fHym0',
'key_map' => 'a:5:{i:0;s:4:"code";i:1;s:5:"email";i:2;s:7:"use_for";i:3;s:6:"domain";i:4;s:15:"hashed_password";}'
);
return $data;
}
add_filter('fansub_kntl_license_defined_data', 'fansub_kntl_license_data');

View File

@ -0,0 +1,2 @@
<?php
if(!function_exists('add_filter')) exit;

1864
custom/fixed functions.txt Normal file

File diff suppressed because it is too large Load Diff

2
custom/index.php Normal file
View File

@ -0,0 +1,2 @@
<?php
# Silence is golden.

1379
custom/shortcode.php Normal file

File diff suppressed because it is too large Load Diff

34
fansub-plugin-main.php Normal file
View File

@ -0,0 +1,34 @@
<?php
/*
Plugin Name: fansub-kntl PLUGINS
Plugin URI: http://fansubs.me/
Description: fansub-kntl plugins CREATE IN BATHROOM WITH LOVE.
Author: KLNsubs
Version: 0.0.1
Author URI: http://fansubs.me/
Text Domain: fansub-kntl
Domain Path: /languages/
*/
if(!function_exists('add_filter')) exit;
define('FANSUB_KNTL_VERSION', '2.3.1');
define('FANSUB_KNTL_FILE', __FILE__);
define('FANSUB_KNTL_PATH', untrailingslashit(plugin_dir_path(FANSUB_KNTL_FILE)));
define('FANSUB_KNTL_URL', plugins_url('', FANSUB_KNTL_FILE));
define('FANSUB_KNTL_INC_PATH', FANSUB_KNTL_PATH . '/inc');
define('FANSUB_KNTL_CUSTOM_PATH', FANSUB_KNTL_PATH . '/custom');
define('FANSUB_KNTL_BASENAME', plugin_basename(FANSUB_KNTL_FILE));
define('FANSUB_KNTL_DIRNAME', dirname(FANSUB_KNTL_BASENAME));
define('FANSUB_KNTL_OPTION_NAME', 'fansub-kntl');
define('FANSUB_KNTL_SETTINGS_URL', 'admin.php?page=' . FANSUB_KNTL_OPTION_NAME);
require_once(FANSUB_KNTL_PATH . '/load.php');

89
fansub/ads.php Normal file
View File

@ -0,0 +1,89 @@
<?php
if(!function_exists('add_filter')) exit;
function fansub_get_ads_positions() {
global $fansub_ads_positions;
$fansub_ads_positions = fansub_sanitize_array($fansub_ads_positions);
$defaults = array(
'leaderboard' => array(
'id' => 'leaderboard',
'name' => __('Leaderboard', 'fansub'),
'description' => __('Display beside logo in header area.', 'fansub')
)
);
$fansub_ads_positions = wp_parse_args($fansub_ads_positions, $defaults);
return apply_filters('fansub_ads_positions', $fansub_ads_positions);
}
function fansub_add_ads_position($args = array()) {
$positions = fansub_get_ads_positions();
$id = fansub_get_value_by_key($args, 'id');
$positions[$id] = $args;
$GLOBALS['fansub_ads_positions'] = $positions;
}
function fansub_show_ads($args = array()) {
if(!is_array($args)) {
$args = array(
'position' => $args
);
}
$position = fansub_get_value_by_key($args, 'position');
if(!empty($position)) {
$random = (bool)fansub_get_value_by_key($args, 'random');
$current_datetime = date(fansub_get_date_format());
$current_datetime = strtotime($current_datetime);
$query_args = array(
'post_type' => 'fansub_ads',
'posts_per_page' => 1,
'meta_query' => array(
'relation' => 'AND',
array(
'relation' => 'OR',
array(
'key' => 'expire',
'compare' => 'NOT EXISTS'
),
array(
'key' => 'expire',
'value' => '',
'compare' => '='
),
array(
'key' => 'expire',
'value' => 0,
'type' => 'numeric'
),
array(
'key' => 'expire',
'value' => $current_datetime,
'type' => 'numeric',
'compare' => '>='
)
),
array(
'key' => 'active',
'value' => 1,
'type' => 'numeric'
)
)
);
if($random) {
$query_args['orderby'] = 'rand';
}
$ads = fansub_get_post_by_meta('position', $position, $query_args);
if($ads->have_posts()) {
$posts = $ads->posts;
$ads = array_shift($posts);
$ads = fansub_get_post_meta('code', $ads->ID);
if(!empty($ads)) {
$class = fansub_get_value_by_key($args, 'class');
fansub_add_string_with_space_before($class, 'fansub-ads text-center ads position-' . $position);
$div = new FANSUB_HTML('div');
$div->set_class($class);
$div->set_text($ads);
$div->output();
}
}
}
}

474
fansub/ajax.php Normal file
View File

@ -0,0 +1,474 @@
<?php
if(!function_exists('add_filter')) exit;
function fansub_debug_log_ajax_callback() {
$object = fansub_get_method_value('object');
$object = fansub_json_string_to_array($object);
fansub_debug_log($object);
exit;
}
add_action('wp_ajax_fansub_debug_log', 'fansub_debug_log_ajax_callback');
add_action('wp_ajax_nopriv_fansub_debug_log', 'fansub_debug_log_ajax_callback');
function fansub_comment_likes_ajax_callback() {
$result = array();
$likes = isset($_POST['likes']) ? absint($_POST['likes']) : 0;
$comment_id = isset($_POST['comment_id']) ? absint($_POST['comment_id']) : 0;
$likes++;
update_comment_meta($comment_id, 'likes', $likes);
$result['likes'] = fansub_number_format($likes);
$_SESSION['comment_' . $comment_id . '_likes'] = 1;
echo json_encode($result);
die();
}
add_action('wp_ajax_fansub_comment_likes', 'fansub_comment_likes_ajax_callback');
add_action('wp_ajax_nopriv_fansub_comment_likes', 'fansub_comment_likes_ajax_callback');
function fansub_comment_report_ajax_callback() {
$result = array();
echo json_encode($result);
die();
}
add_action('wp_ajax_fansub_comment_report', 'fansub_comment_report_ajax_callback');
add_action('wp_ajax_nopriv_fansub_comment_report', 'fansub_comment_report_ajax_callback');
function fansub_fetch_plugin_license_ajax_callback() {
$result = array(
'customer_email' => '',
'license_code' => ''
);
$use_for = isset($_POST['use_for']) ? $_POST['use_for'] : '';
if(!empty($use_for)) {
$use_for_key = md5($use_for);
$option = get_option('fansub_plugin_licenses');
$customer_email = fansub_get_value_by_key($option, array($use_for_key, 'customer_email'));
if(is_array($customer_email) || !is_email($customer_email)) {
$customer_email = '';
}
$license_code = fansub_get_value_by_key($option, array($use_for_key, 'license_code'));
if(is_array($license_code) || strlen($license_code) < 5) {
$license_code = '';
}
$result['customer_email'] = $customer_email;
$result['license_code'] = $license_code;
update_option('test', $result);
}
echo json_encode($result);
die();
}
add_action('wp_ajax_fansub_fetch_plugin_license', 'fansub_fetch_plugin_license_ajax_callback');
function fansub_change_captcha_image_ajax_callback() {
$result = array(
'success' => false
);
$captcha = new FANSUB_Captcha();
$url = $captcha->generate_image();
if(!empty($url)) {
$result['success'] = true;
$result['captcha_image_url'] = $url;
} else {
$result['message'] = __('Sorry, cannot generate captcha image, please try again or contact administrator!', 'fansub');
}
echo json_encode($result);
die();
}
add_action('wp_ajax_fansub_change_captcha_image', 'fansub_change_captcha_image_ajax_callback');
add_action('wp_ajax_nopriv_fansub_change_captcha_image', 'fansub_change_captcha_image_ajax_callback');
function fansub_vote_post_ajax_callback() {
$result = array(
'success' => false
);
$post_id = isset($_POST['post_id']) ? $_POST['post_id'] : '';
$post_id = absint($post_id);
if($post_id > 0) {
$type = isset($_POST['type']) ? $_POST['type'] : fansub_get_method_value('vote_type');
$session_name = 'fansub_vote_' . $type . '_post_' . $post_id;
if(!isset($_SESSION[$session_name]) || 1 != $_SESSION[$session_name]) {
$value = isset($_POST['value']) ? $_POST['value'] : '';
$value = absint($value);
$value++;
if('up' == $type || 'like' == $type) {
update_post_meta($post_id, 'likes', $value);
} elseif('down' == $type || 'dislike' == $type) {
update_post_meta($post_id, 'dislikes', $value);
}
$result['value'] = $value;
$result['type'] = $type;
$result['post_id'] = $post_id;
$result['value_html'] = number_format($value);
$_SESSION[$session_name] = 1;
$result['success'] = true;
}
}
echo json_encode($result);
die();
}
add_action('wp_ajax_fansub_vote_post', 'fansub_vote_post_ajax_callback');
add_action('wp_ajax_nopriv_fansub_vote_post', 'fansub_vote_post_ajax_callback');
function fansub_favorite_post_ajax_callback() {
$result = array(
'html_data' => '',
'success' => false,
'remove' => false
);
$post_id = fansub_get_method_value('post_id');
if(fansub_id_number_valid($post_id) && is_user_logged_in()) {
$user = wp_get_current_user();
$favorites = get_user_meta($user->ID, 'favorite_posts', true);
if(!is_array($favorites)) {
$favorites = array();
}
if(!in_array($post_id, $favorites)) {
$favorites[] = $post_id;
} else {
unset($favorites[array_search($post_id, $favorites)]);
$result['remove'] = true;
}
$updated = update_user_meta($user->ID, 'favorite_posts', $favorites);
if($updated) {
$result['success'] = true;
if($result['remove']) {
$result['html_data'] = '<i class="fa fa-heart-o"></i> Lưu tin';
} else {
$result['html_data'] = '<i class="fa fa-heart"></i> Bỏ lưu';
}
}
}
wp_send_json($result);
}
add_action('wp_ajax_fansub_favorite_post', 'fansub_favorite_post_ajax_callback');
add_action('wp_ajax_nopriv_fansub_favorite_post', 'fansub_favorite_post_ajax_callback');
function fansub_sanitize_media_value_ajax_callback() {
$id = isset($_POST['id']) ? $_POST['id'] : 0;
$url = isset($_POST['url']) ? $_POST['url'] : '';
$result = array('id' => $id, 'url' => $url);
$result = fansub_sanitize_media_value($result);
echo json_encode($result);
exit;
}
add_action('wp_ajax_fansub_sanitize_media_value', 'fansub_sanitize_media_value_ajax_callback');
add_action('wp_ajax_nopriv_fansub_sanitize_media_value', 'fansub_sanitize_media_value_ajax_callback');
function fansub_fetch_administrative_boundaries_ajax_callback() {
$result = array();
$default = fansub_get_method_value('default');
$default = str_replace('\\', '', $default);
//$type = fansub_get_method_value('type');
if(empty($default)) {
}
$html_data = $default;
$parent = fansub_get_method_value('parent');
if(fansub_id_number_valid($parent)) {
$taxonomy = fansub_get_method_value('taxonomy');
if(!empty($taxonomy)) {
$terms = fansub_get_terms($taxonomy, array('parent' => $parent, 'orderby' => 'NAME'));
if(fansub_array_has_value($terms)) {
foreach($terms as $term) {
$option = fansub_field_get_option(array('value' => $term->term_id, 'text' => $term->name));
$html_data .= $option;
}
}
}
}
$result['html_data'] = $html_data;
wp_send_json($result);
}
add_action('wp_ajax_fansub_fetch_administrative_boundaries', 'fansub_fetch_administrative_boundaries_ajax_callback');
add_action('wp_ajax_nopriv_fansub_fetch_administrative_boundaries', 'fansub_fetch_administrative_boundaries_ajax_callback');
function fansub_get_term_ajax_callback() {
$term_id = fansub_get_method_value('term_id');
$result = array(
'term' => new WP_Error()
);
if(fansub_id_number_valid($term_id)) {
$taxonomy = fansub_get_method_value('taxonomy');
if(!empty($taxonomy)) {
$result['term'] = get_term($term_id, $taxonomy);
}
}
wp_send_json($result);
}
add_action('wp_ajax_fansub_get_term', 'fansub_get_term_ajax_callback');
add_action('wp_ajax_nopriv_fansub_get_term', 'fansub_get_term_ajax_callback');
function fansub_get_term_administrative_boundaries_address_ajax_callback() {
$result = array(
'address' => ''
);
$term_id = fansub_get_method_value('term_id');
if(fansub_id_number_valid($term_id)) {
$taxonomy = fansub_get_method_value('taxonomy');
if(!empty($taxonomy)) {
$term = get_term($term_id, $taxonomy);
$address = $term->name;
while($term->parent > 0) {
$address .= ', ';
$term = get_term($term->parent, $taxonomy);
$address .= $term->name;
}
$address = rtrim($address, ', ');
$result['address'] = $address;
}
}
wp_send_json($result);
}
add_action('wp_ajax_fansub_get_term_administrative_boundaries_address', 'fansub_get_term_administrative_boundaries_address_ajax_callback');
add_action('wp_ajax_nopriv_fansub_get_term_administrative_boundaries_address', 'fansub_get_term_administrative_boundaries_address_ajax_callback');
function fansub_dashboard_widget_ajax_callback() {
$result = array(
'html_data' => ''
);
$widget = fansub_get_method_value('widget');
if(!empty($widget)) {
$widgets = explode('_', $widget);
array_shift($widgets);
$widget = implode('_', $widgets);
$callback = 'fansub_theme_dashboard_widget_' . $widget;
if(fansub_callback_exists($callback)) {
ob_start();
call_user_func($callback);
$result['html_data'] = ob_get_clean();
}
}
wp_send_json($result);
}
add_action('wp_ajax_fansub_dashboard_widget', 'fansub_dashboard_widget_ajax_callback');
function fansub_social_login_facebook_ajax_callback() {
$result = array(
'redirect_to' => '',
'logged_in' => false
);
$data = fansub_get_method_value('data');
$data = fansub_json_string_to_array($data);
$connect = (bool)fansub_get_method_value('connect');
if(fansub_array_has_value($data)) {
$verified = (bool)fansub_get_value_by_key($data, 'verified');
$allow_not_verified = apply_filters('fansub_allow_social_user_signup_not_verified', true);
if($verified || $allow_not_verified) {
$id = fansub_get_value_by_key($data, 'id');
$requested_redirect_to = fansub_get_method_value('redirect_to');
$redirect_to = home_url('/');
$transient_name = 'fansub_social_login_facebook_' . md5($id);
$user_id = get_transient($transient_name);
$user = get_user_by('ID', $user_id);
if($connect && is_user_logged_in()) {
$user = wp_get_current_user();
$user_id = $user->ID;
}
$find_users = get_users(array('meta_key' => 'facebook', 'meta_value' => $id));
if(fansub_array_has_value($find_users)) {
$user = $find_users[0];
$user_id = $user->ID;
}
if(false === $user_id || !fansub_id_number_valid($user_id) || !is_a($user, 'WP_User') || $connect) {
$avatar = fansub_get_value_by_key($data, array('picture', 'data', 'url'));
if($connect) {
update_user_meta($user_id, 'facebook', $id);
update_user_meta($user_id, 'facebook_data', $data);
update_user_meta($user_id, 'avatar', $avatar);
$result['redirect_to'] = get_edit_profile_url($user_id);
$result['logged_in'] = true;
} else {
$email = fansub_get_value_by_key($data, 'email');
if(is_email($email)) {
$name = fansub_get_value_by_key($data, 'name');
$first_name = fansub_get_value_by_key($data, 'first_name');
$last_name = fansub_get_value_by_key($data, 'last_name');
$password = wp_generate_password();
$user_id = null;
if(username_exists($email)) {
$user = get_user_by('login', $email);
$user_id = $user->ID;
} elseif(email_exists($email)) {
$user = get_user_by('email', $email);
$user_id = $user->ID;
}
$old_user = true;
if(!fansub_id_number_valid($user_id)) {
$user_data = array(
'username' => $email,
'email' => $email,
'password' => $password
);
$user_id = fansub_add_user($user_data);
if(fansub_id_number_valid($user_id)) {
$old_user = false;
}
}
if(fansub_id_number_valid($user_id)) {
$user = get_user_by('id', $user_id);
$redirect_to = apply_filters('login_redirect', $redirect_to, $requested_redirect_to, $user);
if(!$old_user) {
update_user_meta($user_id, 'facebook', $id);
$user_data = array(
'ID' => $user_id,
'display_name' => $name,
'first_name' => $first_name,
'last_name' => $last_name
);
wp_update_user($user_data);
update_user_meta($user_id, 'avatar', $avatar);
update_user_meta($user_id, 'facebook_data', $data);
}
fansub_user_force_login($user_id);
$result['redirect_to'] = $redirect_to;
$result['logged_in'] = true;
set_transient($transient_name, $user_id, DAY_IN_SECONDS);
}
}
}
} else {
update_user_meta($user_id, 'facebook_data', $data);
$user = get_user_by('id', $user_id);
$redirect_to = apply_filters('login_redirect', $redirect_to, $requested_redirect_to, $user);
fansub_user_force_login($user_id);
$result['redirect_to'] = $redirect_to;
$result['logged_in'] = true;
}
}
}
wp_send_json($result);
}
add_action('wp_ajax_fansub_social_login_facebook', 'fansub_social_login_facebook_ajax_callback');
add_action('wp_ajax_nopriv_fansub_social_login_facebook', 'fansub_social_login_facebook_ajax_callback');
function fansub_social_login_google_ajax_callback() {
$result = array(
'redirect_to' => '',
'logged_in' => false
);
$data = fansub_get_method_value('data');
$data = fansub_json_string_to_array($data);
$connect = fansub_get_method_value('connect');
if(fansub_array_has_value($data)) {
$verified = (bool)fansub_get_value_by_key($data, 'verified');
$allow_not_verified = apply_filters('fansub_allow_social_user_signup_not_verified', true);
if($verified || $allow_not_verified) {
$id = fansub_get_value_by_key($data, 'id');
$requested_redirect_to = fansub_get_method_value('redirect_to');
$redirect_to = home_url('/');
$transient_name = 'fansub_social_login_google_' . md5($id);
$user_id = get_transient($transient_name);
$user = get_user_by('id', $user_id);
if($connect && is_user_logged_in()) {
$user = wp_get_current_user();
$user_id = $user->ID;
}
$find_users = get_users(array('meta_key' => 'google', 'meta_value' => $id));
if(fansub_array_has_value($find_users)) {
$user = $find_users[0];
$user_id = $user->ID;
}
if(false === $user_id || !fansub_id_number_valid($user_id) || !is_a($user, 'WP_User') || $connect) {
$avatar = fansub_get_value_by_key($data, array('image', 'url'));
if($connect) {
update_user_meta($user_id, 'google', $id);
update_user_meta($user_id, 'avatar', $avatar);
update_user_meta($user_id, 'google_data', $data);
$result['redirect_to'] = get_edit_profile_url($user_id);
$result['logged_in'] = true;
} else {
$email = fansub_get_value_by_key($data, array('emails', 0, 'value'));
if(is_email($email)) {
$name = fansub_get_value_by_key($data, 'displayName');
$first_name = fansub_get_value_by_key($data, array('name', 'givenName'));
$last_name = fansub_get_value_by_key($data, array('name', 'familyName'));
$password = wp_generate_password();
$user_id = null;
if(username_exists($email)) {
$user = get_user_by('login', $email);
$user_id = $user->ID;
} elseif(email_exists($email)) {
$user = get_user_by('email', $email);
$user_id = $user->ID;
}
$old_user = true;
if(!fansub_id_number_valid($user_id)) {
$user_data = array(
'username' => $email,
'email' => $email,
'password' => $password
);
$user_id = fansub_add_user($user_data);
if(fansub_id_number_valid($user_id)) {
$old_user = false;
}
}
if(fansub_id_number_valid($user_id)) {
$user = get_user_by('id', $user_id);
$redirect_to = apply_filters('login_redirect', $redirect_to, $requested_redirect_to, $user);
if(!$old_user) {
update_user_meta($user_id, 'google', $id);
$user_data = array(
'ID' => $user_id,
'display_name' => $name,
'first_name' => $first_name,
'last_name' => $last_name
);
wp_update_user($user_data);
update_user_meta($user_id, 'avatar', $avatar);
update_user_meta($user_id, 'google_data', $data);
}
fansub_user_force_login($user_id);
$result['redirect_to'] = $redirect_to;
$result['logged_in'] = true;
set_transient($transient_name, $user_id, DAY_IN_SECONDS);
}
}
}
} else {
update_user_meta($user_id, 'google_data', $data);
$user = get_user_by('id', $user_id);
$redirect_to = apply_filters('login_redirect', $redirect_to, $requested_redirect_to, $user);
fansub_user_force_login($user_id);
$result['redirect_to'] = $redirect_to;
$result['logged_in'] = true;
}
}
}
wp_send_json($result);
}
add_action('wp_ajax_fansub_social_login_google', 'fansub_social_login_google_ajax_callback');
add_action('wp_ajax_nopriv_fansub_social_login_google', 'fansub_social_login_google_ajax_callback');
function fansub_disconnect_social_account_ajax_callback() {
$social = fansub_get_method_value('social');
$user_id = fansub_get_method_value('user_id');
if(fansub_id_number_valid($user_id)) {
switch($social) {
case 'facebook':
delete_user_meta($user_id, 'facebook');
delete_user_meta($user_id, 'facebook_data');
break;
case 'google':
delete_user_meta($user_id, 'google');
delete_user_meta($user_id, 'google_data');
break;
}
}
exit;
}
add_action('wp_ajax_fansub_disconnect_social_account', 'fansub_disconnect_social_account_ajax_callback');
function fansub_compress_style_and_script_ajax_callback() {
$result = array();
$type = fansub_get_method_value('type');
$type = fansub_json_string_to_array($type);
$force_compress = fansub_get_method_value('force_compress');
$args = array(
'type' => $type,
'force_compress' => $force_compress
);
fansub_compress_style_and_script($args);
wp_send_json($result);
}
add_action('wp_ajax_fansub_compress_style_and_script', 'fansub_compress_style_and_script_ajax_callback');

23
fansub/api.php Normal file
View File

@ -0,0 +1,23 @@
<?php
if(!function_exists('add_filter')) exit;
$plugins = get_option('active_plugins');
if(!is_array($plugins) || !in_array('rest-api/plugin.php', $plugins)) {
return;
}
function fansub_api_allow_meta_query($valid_vars) {
$valid_vars = array_merge($valid_vars, array('meta_key', 'meta_value', 'meta_query'));
return $valid_vars;
}
add_filter('rest_query_vars', 'fansub_api_allow_meta_query');
function fansub_api_get_by_meta($meta_query, $rest_base, $version = 'v2', $server = HOCWP_API_SERVER) {
$fields = array(
'filter[meta_query]' => $meta_query
);
$meta_query = http_build_query($fields);
$url = trailingslashit($server) . 'wp-json/wp/' . $version . '/' . $rest_base . '?' . $meta_query;
return json_decode(@file_get_contents($url));
}

26
fansub/back-end.php Normal file
View File

@ -0,0 +1,26 @@
<?php
if(!function_exists('add_filter')) exit;
function fansub_upgrader_process_complete($upgrader, $options) {
$type = fansub_get_value_by_key($options, 'type');
switch($type) {
case 'plugin':
do_action('fansub_plugin_upgrader_process_complete', $upgrader, $options);
break;
}
}
add_action('upgrader_process_complete', 'fansub_upgrader_process_complete', 10, 2);
function fansub_plugin_upgrader_process_complete($upgrader, $options) {
$plugins = fansub_get_value_by_key($options, 'plugins');
if(!fansub_array_has_value($plugins)) {
return;
}
foreach($plugins as $plugin) {
$slug = fansub_get_plugin_slug_from_file_path($plugin);
$transient_name = 'fansub_plugins_api_' . $slug . '_plugin_information';
$transient_name = fansub_sanitize_id($transient_name);
delete_transient($transient_name);
}
}
add_action('fansub_plugin_upgrader_process_complete', 'fansub_plugin_upgrader_process_complete', 10, 2);

View File

@ -0,0 +1,420 @@
<?php
if(!function_exists('add_filter')) exit;
class FANSUB_Captcha {
private $chars;
private $length;
private $fonts;
private $background;
private $foreground;
private $code;
private $uppercase;
private $lowercase;
private $size;
private $base;
private $font_size;
private $file_mode;
private $image_type;
private $font_char_width;
private $save_path;
private $save_url;
private $session_name;
private $expired_minutes;
private $pixel;
private $pixel_color;
private $line;
private $line_color;
public function set_expired_minutes($minutes) {
$this->expired_minutes = $minutes;
}
public function get_expired_minutes() {
return $this->expired_minutes;
}
public function set_session_name($name) {
$this->session_name = $name;
}
public function get_session_name() {
return $this->session_name;
}
public function set_save_path($path) {
$this->save_path = $path;
}
public function get_save_path() {
return $this->save_path;
}
public function set_save_url($url) {
$this->save_url = $url;
}
public function get_save_url() {
return $this->save_url;
}
public function set_font_char_width($width) {
$this->font_char_width = $width;
}
public function get_font_char_width() {
return $this->font_char_width;
}
public function set_image_type($type) {
$this->image_type = $type;
}
public function get_image_type() {
return $this->image_type;
}
public function set_file_mode($mode) {
$this->file_mode = $mode;
}
public function get_file_mode() {
return $this->file_mode;
}
public function set_font_size($font_size) {
$this->font_size = $font_size;
}
public function get_font_size() {
return $this->font_size;
}
public function set_base($base) {
$this->base = $base;
}
public function get_base() {
return $this->base;
}
public function set_size($size) {
$this->size = $size;
}
public function get_size() {
return $this->size;
}
public function set_width($width) {
$this->size[0] = $width;
}
public function set_height($height) {
$this->size[1] = $height;
}
public function set_uppercase($uppercase) {
$this->uppercase = $uppercase;
}
public function get_uppercase() {
return $this->uppercase;
}
public function set_lowercase($lowercase) {
$this->lowercase = $lowercase;
}
public function get_lowercase() {
return $this->lowercase;
}
public function set_code($code) {
$this->code = $code;
}
public function get_code() {
return $this->code;
}
public function set_foreground($fg) {
$this->foreground = $fg;
}
public function get_foreground() {
return $this->foreground;
}
public function set_background($bg) {
$this->background = $bg;
}
public function get_background() {
return $this->background;
}
public function set_fonts($fonts) {
$this->fonts = $fonts;
}
public function add_font($font) {
$this->fonts[] = $font;
}
public function get_fonts() {
return $this->fonts;
}
public function set_length($length) {
$this->length = $length;
}
public function get_length() {
return $this->length;
}
public function set_chars($chars) {
$this->chars = $chars;
}
public function get_chars() {
return $this->chars;
}
public function set_pixel($bool) {
$this->pixel = $bool;
}
public function get_pixel() {
return (bool)$this->pixel;
}
public function set_pixel_color($color) {
$this->pixel_color = $color;
}
public function get_pixel_color() {
return $this->pixel_color;
}
public function set_line($bool) {
$this->line = $bool;
}
public function get_line() {
return (bool)$this->line;
}
public function set_line_color($color) {
$this->line_color = $color;
}
public function get_line_color() {
return $this->line_color;
}
public function __construct() {
$defaults = array(
'chars' => fansub_get_safe_captcha_characters(),
'length' => 5,
'uppercase' => true,
'lowercase' => true,
'size' => array(87, 25),
'background' => array(255, 255, 255),
'foreground' => array(138, 200, 67),
'pixel' => true,
'pixel_color' => array(205, 255, 205),
'line' => true,
'line_color' => array(205, 215, 205),
'font_char_width' => 14,
'file_mode' => 0444,
'image_type' => 'png',
'font_size' => 13,
'base' => array(10, 20),
'save_path' => FANSUB_CONTENT_PATH . '/captcha',
'save_url' => content_url('fansub/captcha'),
'session_name' => 'fansub_captcha',
'expired_minutes' => 3,
'fonts' => array(FANSUB_PATH . '/fonts/Tahoma.ttf')
);
$args = apply_filters('fansub_captcha_default_args', array());
$args = wp_parse_args($args, $defaults);
$this->set_chars($args['chars']);
$this->set_length($args['length']);
$this->set_uppercase($args['uppercase']);
$this->set_lowercase($args['lowercase']);
$this->set_size($args['size']);
$this->set_background($args['background']);
$this->set_foreground($args['foreground']);
$this->set_line($args['line']);
$this->set_line_color($args['line_color']);
$this->set_pixel($args['pixel']);
$this->set_pixel_color($args['pixel_color']);
$this->set_font_char_width($args['font_char_width']);
$this->set_file_mode($args['file_mode']);
$this->set_image_type($args['image_type']);
$this->set_font_size($args['font_size']);
$this->set_base($args['base']);
$this->set_save_path($args['save_path']);
$this->set_save_url($args['save_url']);
$this->set_session_name($args['session_name']);
$this->set_fonts($args['fonts']);
$this->set_expired_minutes($args['expired_minutes']);
}
public function generate_image() {
$dir = wp_normalize_path($this->get_save_path());
if(!wp_mkdir_p($dir)) {
return false;
}
$this->cleanup_expired();
$code = fansub_random_string($this->get_length(), $this->get_chars());
$filename = '';
$dir = trailingslashit($dir);
if($this->get_uppercase()) {
$code = strtoupper($code);
}
$size = $this->get_size();
if($im = @imagecreatetruecolor($size[0], $size[1])) {
$fonts = $this->get_fonts();
if(!fansub_array_has_value($fonts)) {
return false;
}
$filename = md5(fansub_random_string());
$background = $this->get_background();
$foreground = $this->get_foreground();
$bg = @imagecolorallocate($im, $background[0], $background[1], $background[2]);
$fg = @imagecolorallocate($im, $foreground[0], $foreground[1], $foreground[2]);
@imagefill($im, 0, 0, $bg);
if($this->get_pixel()) {
$pixel_colors = $this->get_pixel_color();
$pixel_color = @imagecolorallocate($im, $pixel_colors[0], $pixel_colors[1], $pixel_colors[2]);
$pixels = rand(300, 600);
for($i = 0; $i < $pixels; $i++) {
@imagesetpixel($im, rand(1, 100), rand(1, 100), $pixel_color);
}
}
$base = $this->get_base();
$x = $base[0] + mt_rand(-2, 2);
for($i = 0; $i < strlen($code); $i++) {
$font = $fonts[array_rand($fonts)];
$font = wp_normalize_path($font);
$y = $base[1] + mt_rand(-2, 2);
$angle = mt_rand(-20, 20);
@imagettftext($im, $this->get_font_size(), $angle, $x, $y, $fg, $font, $code[$i]);
$x += $this->get_font_char_width();
}
if($this->get_line()) {
$lines = rand(5, 10);
$line_colors = $this->get_line_color();
$line_color = @imagecolorallocate($im, $line_colors[0], $line_colors[1], $line_colors[2]);
for($i = 0; $i < $lines; $i++) {
@imageline($im, rand(1, 100), rand(1, 100), rand(1, 100), rand(1, 100), $line_color);
}
}
switch($this->get_image_type()) {
case 'jpeg':
$filename = sanitize_file_name($filename. '.jpeg');
$file = wp_normalize_path($dir . $filename);
@imagejpeg($im, $file);
break;
case 'gif':
$filename = sanitize_file_name($filename . '.gif');
$file = wp_normalize_path($dir . $filename);
@imagegif($im, $file);
break;
case 'png':
default:
$filename = sanitize_file_name($filename . '.png');
$file = wp_normalize_path($dir . $filename);
@imagepng($im, $file);
}
@imagedestroy($im);
@chmod($file, $this->get_file_mode());
}
if(!empty($filename)) {
if($this->get_lowercase()) {
$code = strtolower($code);
}
$data = array(
'hashed' => wp_hash_password($code),
'timestamp' => strtotime(fansub_get_current_date('Y-m-d H:i:s'))
);
$this->set_session_data($data);
}
$this->set_code($code);
return trailingslashit($this->get_save_url()) . $filename;
}
public function get_session_data() {
$session_name = $this->get_session_name();
$captcha_session = isset($_SESSION[$session_name]) ? maybe_unserialize($_SESSION[$session_name]) : array();
return $captcha_session;
}
public function set_session_data($data) {
$session_name = $this->get_session_name();
$_SESSION[$session_name] = maybe_serialize($data);
}
public function check($code) {
$current_datetime = fansub_get_current_date('Y-m-d H:i:s');
$captcha_session = $this->get_session_data();
$timestamp = fansub_get_value_by_key($captcha_session, 'timestamp');
if(!is_numeric($timestamp)) {
return false;
}
if(strtotime('+' . strval($this->get_expired_minutes()) . ' minutes', $timestamp) < strtotime($current_datetime)) {
return false;
}
if($this->get_lowercase()) {
$code = strtolower($code);
}
$save_code = fansub_get_value_by_key($captcha_session, 'hashed');
return wp_check_password($code, $save_code);
}
public function remove($prefix) {
$suffixes = array('.jpeg', '.gif', '.png', '.php', '.txt');
foreach($suffixes as $suffix) {
$dir = trailingslashit($this->get_save_path());
$filename = sanitize_file_name($prefix . $suffix);
$file = wp_normalize_path($dir . $filename);
if(@is_file($file)) {
@unlink($file);
}
}
}
public function cleanup_expired($minutes = 60) {
$dir = trailingslashit($this->get_save_path());
$dir = wp_normalize_path($dir);
if(!@is_dir($dir) || !@is_readable($dir)) {
return false;
}
$is_win = ('WIN' === strtoupper(substr(PHP_OS, 0, 3)));
if(!($is_win ? win_is_writable($dir) : @is_writable($dir))) {
return false;
}
fansub_delete_old_file($dir, $minutes * MINUTE_IN_SECONDS);
$count = 0;
if($handle = @opendir($dir)) {
while(false !== ($filename = readdir($handle))) {
if(!preg_match('/^[0-9]+\.(php|txt|png|gif|jpeg)$/', $filename)) {
continue;
}
$file = wp_normalize_path($dir . $filename);
$stat = @stat($file);
if(($stat['mtime'] + $minutes * MINUTE_IN_SECONDS) < time()) {
@unlink($file);
$count += 1;
}
}
closedir($handle);
}
return $count;
}
}

View File

@ -0,0 +1,203 @@
<?php
if(!function_exists('add_filter')) exit;
if(defined('FANSUB_HTML_VERSION')) {
return;
}
define('FANSUB_HTML_VERSION', '1.0.0');
class FANSUB_HTML {
private $self_closers = array();
public $name = null;
public $attributes = array();
public $break_line = true;
public $close = true;
public $only_text = false;
public $wrap_tag = '';
public function set_close($close) {
$this->close = $close;
}
public function get_close() {
return $this->close;
}
public function __construct($name) {
$this->set_name($name);
if('img' == $name) {
$this->set_image_alt("");
}
}
public function get_name() {
return $this->name;
}
public function set_name($name) {
$this->name = strtolower($name);
}
public function use_only_text() {
$this->only_text = true;
}
public function get_self_closers() {
$self_closers = array('input', 'img', 'hr', 'br', 'meta', 'link');
$this->set_self_closers($self_closers);
return $this->self_closers;
}
private function set_self_closers($self_closers) {
$this->self_closers = $self_closers;
}
public function get_attribute($attribute_name) {
if($this->is_attribute_exists($attribute_name)) {
return $this->attributes[$attribute_name];
}
return null;
}
public function set_attribute($attribute_name, $value) {
$this->attributes[$attribute_name] = $value;
}
public function set_image_src($src) {
$this->set_attribute('src', $src);
}
public function set_image_alt($alt) {
$this->set_attribute('alt', $alt);
}
public function set_class($class) {
$this->set_attribute('class', $class);
}
public function set_id($id) {
$id = fansub_sanitize_id($id);
$this->set_attribute('id', $id);
}
public function add_class($class) {
$old_class = $this->get_attribute('class');
fansub_add_string_with_space_before($old_class, $class);
$this->set_class($old_class);
}
public function set_href($href) {
$this->set_attribute('href', $href);
}
public function set_html($value) {
$this->set_attribute('text', $value);
}
public function set_text($value) {
if(is_a($value, 'FANSUB_HTML')) {
$value = $value->build();
}
if('input' == $this->get_name()) {
$this->set_attribute('value', $value);
} else {
$this->set_html($value);
}
}
public function set_attribute_array($attributes) {
if(is_array($attributes)) {
$this->attributes = wp_parse_args($attributes, $this->attributes);
}
}
public function remove_attribute($attribute_name) {
if($this->is_attribute_exists($attribute_name)) {
unset($this->attributes[$attribute_name]);
}
}
public function text_exsits() {
$text = $this->get_attribute('text');
if(!empty($text)) {
return true;
}
return false;
}
public function remove_all_attribute() {
$this->attributes = array();
}
private function make_outlink_nofollow() {
if('a' == $this->get_name()) {
$href = $this->get_attribute('href');
if(!empty($href)) {
if(!fansub_is_site_domain($href)) {
$this->set_attribute('rel', 'external nofollow');
$this->set_attribute('target', '_blank');
}
}
}
}
private function check_html() {
$this->make_outlink_nofollow();
}
public function build() {
$wrap_tag = $this->get_wrap_tag();
if($this->only_text) {
return $this->get_attribute('text');
}
$this->check_html();
$html_name = $this->get_name();
$result = '<' . $html_name;
if(!empty($wrap_tag)) {
$result = '<' . $wrap_tag . '>' . $result;
}
foreach($this->attributes as $key => $value) {
if($key != 'text') {
$result .= sprintf(' %1$s="%2$s"', $key, trim(esc_attr($value)));
}
}
$result .= '>';
if(!in_array($html_name, $this->get_self_closers())) {
$text = $this->get_attribute('text');
$result .= $text;
}
if($this->get_close() && !in_array($html_name, $this->get_self_closers())) {
$result .= sprintf('</%s>', $html_name);
}
if(!empty($wrap_tag)) {
$result .= '</' . $wrap_tag . '>';
}
return $result;
}
public function set_break_line($break_line) {
$this->break_line = $break_line;
}
public function get_break_line() {
return $this->break_line;
}
public function output() {
$html = $this->build();
if($this->get_break_line()) {
$html .= PHP_EOL;
}
echo $html;
}
public function is_attribute_exists($attribute_name) {
return array_key_exists($attribute_name, $this->attributes);
}
public function set_wrap_tag($tag) {
$this->wrap_tag = $tag;
}
public function get_wrap_tag() {
return $this->wrap_tag;
}
}

View File

@ -0,0 +1,338 @@
<?php
if(!function_exists('add_filter')) exit;
class FANSUB_License {
private $hashed_password;
private $key;
private $key_map;
private $customer_name;
private $customer_email;
private $customer_phone;
private $customer_identity;
private $customer_url;
private $code;
private $hashed_code;
private $use_for;
private $domain;
private $password;
private $option;
private $type;
private $option_name;
private $valid;
private $generation;
private $generated;
public function set_generated($generated) {
$this->generated = $generated;
}
public function get_generated() {
return $this->generated;
}
public function set_generation($generation) {
$this->generation = $generation;
}
public function get_generation() {
return $this->generation;
}
public function set_valid($valid) {
$this->valid = $valid;
}
public function get_valid() {
return $this->valid;
}
public function set_option_name($option_name) {
$this->option_name = $option_name;
}
public function get_option_name() {
return $this->option_name;
}
public function set_type($type) {
$this->type = $type;
}
public function get_type() {
return $this->type;
}
public function set_option(FANSUB_Option $option) {
$this->option = $option;
}
public function get_option() {
return $this->option;
}
public function set_password($password) {
$this->password = $password;
}
public function get_password() {
return $this->password;
}
public function set_domain($domain) {
$domain = esc_url($domain);
$domain = fansub_get_root_domain_name($domain);
$this->domain = $domain;
}
public function get_domain() {
return $this->domain;
}
public function set_use_for($use_for) {
$this->use_for = $use_for;
}
public function get_use_for() {
return $this->use_for;
}
public function set_hashed_code($hashed_code) {
$this->hashed_code = $hashed_code;
}
public function get_hashed_code() {
return $this->hashed_code;
}
public function set_code($code) {
$this->code = $code;
}
public function get_code() {
return $this->code;
}
public function set_customer_url($customer_url) {
$customer_url = trailingslashit($customer_url);
$this->customer_url = $customer_url;
}
public function get_customer_url() {
return $this->customer_url;
}
public function set_customer_identity($customer_identity) {
$this->customer_identity = $customer_identity;
}
public function get_customer_identity() {
return $this->customer_identity;
}
public function set_customer_phone($customer_phone) {
$this->customer_phone = $customer_phone;
}
public function get_customer_phone() {
return $this->customer_phone;
}
public function set_customer_email($customer_email) {
$this->customer_email = $customer_email;
}
public function get_customer_email() {
return $this->customer_email;
}
public function set_customer_name($customer_name) {
$this->customer_name = $customer_name;
}
public function get_customer_name() {
return $this->customer_name;
}
public function set_hashed_password($hashed_password) {
$this->hashed_password = $hashed_password;
}
public function get_hashed_password() {
return $this->hashed_password;
}
public function set_key($key) {
$this->key = $key;
}
public function get_key() {
return $this->key;
}
public function set_key_map($key_map) {
$this->key_map = $key_map;
}
public function get_key_map() {
return $this->key_map;
}
public function __construct() {
$this->set_hashed_password(FANSUB_HASHED_PASSWORD);
$this->set_key('');
$this->set_type('theme');
$this->set_use_for(get_option('template'));
$this->set_domain(home_url());
$this->set_customer_url(home_url('/'));
$this->set_customer_email(get_option('admin_email'));
$option = fansub_option_get_object_from_list('theme_license');
if(fansub_object_valid($option)) {
$this->set_option($option);
}
if(fansub_object_valid($option)) {
$this->set_option_name($option->get_option_name());
}
}
public function build_key_map() {
$pieces = array();
$email = $this->get_customer_email();
$phone = $this->get_customer_phone();
$identity = $this->get_customer_identity();
if(empty($email) && empty($phone) && empty($identity)) {
return $pieces;
}
if(!empty($email)) {
$pieces[] = 'email';
}
if(!empty($phone)) {
$pieces[] = 'phone';
}
if(!empty($identity)) {
$pieces[] = 'identity';
}
$pieces[] = 'code';
$pieces[] = 'domain';
$pieces[] = 'use_for';
shuffle($pieces);
$pieces[] = 'hashed_password';
$pieces = fansub_sanitize_array($pieces);
$this->set_key_map($pieces);
return $pieces;
}
public function get_map_key_value($key) {
$value = '';
switch($key) {
case 'email':
$value = $this->get_customer_email();
break;
case 'phone':
$value = $this->get_customer_phone();
break;
case 'identity':
$value = $this->get_customer_identity();
break;
case 'code':
$value = $this->get_code();
break;
case 'domain':
$value = $this->get_domain();
break;
case 'use_for':
$value = $this->get_use_for();
break;
default:
if(!$this->get_generation() || $this->compare_password()) {
$value = $this->get_hashed_password();
}
break;
}
return $value;
}
public function get_saved_license_data() {
return get_option($this->get_option_name());
}
public function get_saved_generated_data() {
$data = get_option('fansub_license');
$value = fansub_get_value_by_key($data, array($this->get_type(), md5($this->get_use_for())));
return $value;
}
public function create_key() {
if($this->get_generation()) {
$pieces = $this->build_key_map();
} else {
$pieces = $this->get_key_map();
if(!fansub_array_has_value($pieces)) {
$data = $this->get_saved_generated_data();
$pieces = fansub_get_value_by_key($data, 'key_map');
}
}
$result = '';
if(count($pieces) >= 3) {
foreach($pieces as $piece) {
if(!empty($piece)) {
$value = $this->get_map_key_value($piece);
if(!empty($value)) {
if(is_array($value)) {
$value = implode('_', $value);
}
$result .= $value . '_';
}
}
}
}
$result = trim($result, '_');
$this->set_key($result);
return $result;
}
public function compare_password() {
return wp_check_password($this->get_password(), $this->get_hashed_password());
}
public function generate() {
$result = array();
if(!$this->compare_password()) {
$result = new WP_Error('set_fansub_password', __('Please set default HocWP password first!', 'fansub'));
} else {
$this->set_generation(true);
$this->create_key();
$this->set_hashed_code(wp_hash_password($this->get_key()));
$url = $this->get_customer_url();
if(!empty($url)) {
$url = add_query_arg(array(
'hashed' => $this->get_hashed_code(),
'key_map' => $this->get_key_map(),
'type' => $this->get_type(),
'use_for' => $this->get_use_for(),
'fansub_password' => $this->get_password()
), $url);
$result['url'] = $url;
}
$result['code'] = $this->get_code();
$result['customer_email'] = $this->get_customer_email();
$result['hashed'] = $this->get_hashed_code();
$result['key_map'] = $this->get_key_map();
}
$this->set_generated($result);
return $result;
}
public function for_theme() {
if('theme' == $this->get_type()) {
return true;
}
return false;
}
public function get_transient_name() {
return fansub_build_license_transient_name($this->get_type(), $this->get_use_for());
}
public function check_valid($data = array()) {
return true;
}
}

View File

@ -0,0 +1,191 @@
<?php
if(!function_exists('add_filter')) exit;
class FANSUB_Menu_Edit_Walker extends Walker_Nav_Menu {
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
global $_wp_nav_menu_max_depth;
$_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
ob_start();
$item_id = esc_attr( $item->ID );
$removed_args = array(
'action',
'customlink-tab',
'edit-menu-item',
'menu-item',
'page-tab',
'_wpnonce',
);
$original_title = '';
if ( 'taxonomy' == $item->type ) {
$original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
if ( is_wp_error( $original_title ) )
$original_title = false;
} elseif ( 'post_type' == $item->type ) {
$original_object = get_post( $item->object_id );
$original_title = get_the_title( $original_object->ID );
} elseif ( 'post_type_archive' == $item->type ) {
$original_object = get_post_type_object( $item->object );
if ( $original_object ) {
$original_title = $original_object->labels->archives;
}
}
$classes = array(
'menu-item menu-item-depth-' . $depth,
'menu-item-' . esc_attr( $item->object ),
'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'),
);
$title = $item->title;
if ( ! empty( $item->_invalid ) ) {
$classes[] = 'menu-item-invalid';
/* translators: %s: title of menu item which is invalid */
$title = sprintf( __( '%s (Invalid)' ), $item->title );
} elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
$classes[] = 'pending';
/* translators: %s: title of menu item in draft status */
$title = sprintf( __('%s (Pending)'), $item->title );
}
$title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label;
$submenu_text = '';
if ( 0 == $depth )
$submenu_text = 'style="display: none;"';
?>
<li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>">
<div class="menu-item-bar">
<div class="menu-item-handle">
<span class="item-title"><span class="menu-item-title"><?php echo esc_html( $title ); ?></span> <span class="is-submenu" <?php echo $submenu_text; ?>><?php _e( 'sub item' ); ?></span></span>
<span class="item-controls">
<span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
<span class="item-order hide-if-js">
<a href="<?php
echo wp_nonce_url(
add_query_arg(
array(
'action' => 'move-up-menu-item',
'menu-item' => $item_id,
),
remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
),
'move-menu_item'
);
?>" class="item-move-up" aria-label="<?php esc_attr_e( 'Move up' ) ?>">&#8593;</a>
|
<a href="<?php
echo wp_nonce_url(
add_query_arg(
array(
'action' => 'move-down-menu-item',
'menu-item' => $item_id,
),
remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
),
'move-menu_item'
);
?>" class="item-move-down" aria-label="<?php esc_attr_e( 'Move down' ) ?>">&#8595;</a>
</span>
<a class="item-edit" id="edit-<?php echo $item_id; ?>" href="<?php
echo ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? admin_url( 'nav-menus.php' ) : add_query_arg( 'edit-menu-item', $item_id, remove_query_arg( $removed_args, admin_url( 'nav-menus.php#menu-item-settings-' . $item_id ) ) );
?>" aria-label="<?php esc_attr_e( 'Edit menu item' ); ?>"><?php _e( 'Edit' ); ?></a>
</span>
</div>
</div>
<div class="menu-item-settings wp-clearfix" id="menu-item-settings-<?php echo $item_id; ?>">
<?php if ( 'custom' == $item->type ) : ?>
<p class="field-url description description-wide">
<label for="edit-menu-item-url-<?php echo $item_id; ?>">
<?php _e( 'URL' ); ?><br />
<input type="text" id="edit-menu-item-url-<?php echo $item_id; ?>" class="widefat code edit-menu-item-url" name="menu-item-url[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->url ); ?>" />
</label>
</p>
<?php endif; ?>
<p class="description description-wide">
<label for="edit-menu-item-title-<?php echo $item_id; ?>">
<?php _e( 'Navigation Label' ); ?><br />
<input type="text" id="edit-menu-item-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-title" name="menu-item-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->title ); ?>" />
</label>
</p>
<p class="field-title-attribute field-attr-title description description-wide">
<label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
<?php _e( 'Title Attribute' ); ?><br />
<input type="text" id="edit-menu-item-attr-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->post_excerpt ); ?>" />
</label>
</p>
<p class="field-link-target description">
<label for="edit-menu-item-target-<?php echo $item_id; ?>">
<input type="checkbox" id="edit-menu-item-target-<?php echo $item_id; ?>" value="_blank" name="menu-item-target[<?php echo $item_id; ?>]"<?php checked( $item->target, '_blank' ); ?> />
<?php _e( 'Open link in a new tab' ); ?>
</label>
</p>
<p class="field-css-classes description description-thin">
<label for="edit-menu-item-classes-<?php echo $item_id; ?>">
<?php _e( 'CSS Classes (optional)' ); ?><br />
<input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo esc_attr( implode(' ', $item->classes ) ); ?>" />
</label>
</p>
<p class="field-xfn description description-thin">
<label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
<?php _e( 'Link Relationship (XFN)' ); ?><br />
<input type="text" id="edit-menu-item-xfn-<?php echo $item_id; ?>" class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->xfn ); ?>" />
</label>
</p>
<p class="field-description description description-wide">
<label for="edit-menu-item-description-<?php echo $item_id; ?>">
<?php _e( 'Description' ); ?><br />
<textarea id="edit-menu-item-description-<?php echo $item_id; ?>" class="widefat edit-menu-item-description" rows="3" cols="20" name="menu-item-description[<?php echo $item_id; ?>]"><?php echo esc_html( $item->description ); // textarea_escaped ?></textarea>
<span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.'); ?></span>
</label>
</p>
<?php do_action('fansub_edit_menu_item_field', $item, $args, $depth); ?>
<p class="field-move hide-if-no-js description description-wide">
<label>
<span><?php _e( 'Move' ); ?></span>
<a href="#" class="menus-move menus-move-up" data-dir="up"><?php _e( 'Up one' ); ?></a>
<a href="#" class="menus-move menus-move-down" data-dir="down"><?php _e( 'Down one' ); ?></a>
<a href="#" class="menus-move menus-move-left" data-dir="left"></a>
<a href="#" class="menus-move menus-move-right" data-dir="right"></a>
<a href="#" class="menus-move menus-move-top" data-dir="top"><?php _e( 'To the top' ); ?></a>
</label>
</p>
<div class="menu-item-actions description-wide submitbox">
<?php if ( 'custom' != $item->type && $original_title !== false ) : ?>
<p class="link-to-original">
<?php printf( __('Original: %s'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
</p>
<?php endif; ?>
<a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php
echo wp_nonce_url(
add_query_arg(
array(
'action' => 'delete-menu-item',
'menu-item' => $item_id,
),
admin_url( 'nav-menus.php' )
),
'delete-menu_item_' . $item_id
); ?>"><?php _e( 'Remove' ); ?></a> <span class="meta-sep hide-if-no-js"> | </span> <a class="item-cancel submitcancel hide-if-no-js" id="cancel-<?php echo $item_id; ?>" href="<?php echo esc_url( add_query_arg( array( 'edit-menu-item' => $item_id, 'cancel' => time() ), admin_url( 'nav-menus.php' ) ) );
?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel'); ?></a>
</div>
<input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" />
<input class="menu-item-data-object-id" type="hidden" name="menu-item-object-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object_id ); ?>" />
<input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
<input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_item_parent ); ?>" />
<input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
<input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
</div><!-- .menu-item-settings-->
<ul class="menu-item-transport"></ul>
<?php
$output .= ob_get_clean();
}
}

View File

@ -0,0 +1,45 @@
<?php
if(!function_exists('add_filter')) exit;
class FANSUB_Menu_Walker extends Walker_Nav_Menu {
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
$menu_title = $item->title;
$menu_title_slug = fansub_sanitize_file_name($menu_title);
$indent = ($depth) ? str_repeat("\t", $depth) : '';
$classes = empty($item->classes) ? array() : (array)$item->classes;
$classes[] = 'menu-item-' . $item->ID;
$classes[] = 'menu-' . $menu_title_slug;
$class_names = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item, $args, $depth));
$class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : '';
$id = apply_filters('nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args, $depth);
$id = $id ? ' id="' . esc_attr($id) . '"' : '';
$output .= $indent . '<li' . $id . $class_names .'>';
$atts = array();
$atts['title'] = ! empty($item->attr_title) ? $item->attr_title : '';
$atts['target'] = ! empty($item->target) ? $item->target : '';
$atts['rel'] = ! empty($item->xfn) ? $item->xfn : '';
$atts['href'] = ! empty($item->url) ? $item->url : '';
$atts = apply_filters('nav_menu_link_attributes', $atts, $item, $args, $depth);
$attributes = '';
foreach($atts as $attr => $value) {
if(!empty($value)) {
$value = ('href' === $attr) ? esc_url($value) : esc_attr($value);
$attributes .= ' ' . $attr . '="' . $value . '"';
}
}
$item_output = $args->before;
$item_output .= '<a'. $attributes .'>';
$item_output .= $args->link_before;
$item_output = apply_filters('fansub_menu_item_output_link_text_before', $item_output, $item, $args, $depth);
$link_text = apply_filters('the_title', $item->title, $item->ID);
$item_output .= apply_filters('fansub_menu_item_output_link_text', $link_text, $item, $args, $depth);
if(!empty($item->description)) {
$item_output .= '<span class="description">' . $item->description . '</span>';
}
$item_output = apply_filters('fansub_menu_item_output_link_text_after', $item_output, $item, $args, $depth);
$item_output .= $args->link_after;
$item_output .= '</a>';
$item_output .= $args->after;
$output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args);
}
}

View File

@ -0,0 +1,571 @@
<?php
if(!function_exists('add_filter')) exit;
class FANSUB_Meta {
private $type;
private $fields;
private $callback;
private $id;
private $post_types;
private $title;
private $context;
private $priority;
private $callback_args;
private $show;
private $taxonomies;
private $add_callback;
private $translation;
private $column;
private $edit_callback;
private $use_media_upload = false;
private $use_color_picker = false;
private $use_datetime_picker = false;
private $use_select_chosen = false;
public function set_use_select_chosen($use) {
$this->use_select_chosen = $use;
}
public function get_use_select_chosen() {
return (bool)$this->use_select_chosen;
}
public function set_use_datetime_picker($use) {
$this->use_datetime_picker = $use;
}
public function get_use_datetime_picker() {
return (bool)$this->use_datetime_picker;
}
public function set_use_color_picker($use) {
$this->use_color_picker = $use;
}
public function get_use_color_picker() {
return (bool)$this->use_color_picker;
}
public function set_edit_callback($edit_callback) {
$this->edit_callback = $edit_callback;
}
public function get_edit_callback() {
return $this->edit_callback;
}
public function set_use_media_upload($use) {
$this->use_media_upload = $use;
}
public function get_use_media_upload() {
return (bool)$this->use_media_upload;
}
public function set_column($column) {
$this->column = $column;
}
public function get_column() {
return $this->column;
}
public function set_translation($translation) {
$this->translation = $translation;
}
public function get_translation() {
return $this->translation;
}
public function set_add_callback($add_callback) {
$this->add_callback = $add_callback;
}
public function get_add_callback() {
return $this->add_callback;
}
public function set_taxonomies($taxonomies) {
$this->taxonomies = $taxonomies;
}
public function get_taxonomies() {
return $this->taxonomies;
}
public function add_taxonomy($taxonomy) {
$this->taxonomies[] = $taxonomy;
$this->set_taxonomies(fansub_sanitize_array($this->get_taxonomies()));
}
public function set_show($show) {
$this->show = $show;
}
public function get_show() {
return $this->show;
}
public function set_callback_args($callback_args) {
$this->callback_args = $callback_args;
}
public function get_callback_args() {
return $this->callback_args;
}
public function set_priority($priority) {
$this->priority = $priority;
}
public function get_priority() {
return $this->priority;
}
public function set_context($context) {
$this->context = $context;
}
public function get_context() {
return $this->context;
}
public function set_callback($callback) {
$this->callback = $callback;
}
public function get_callback() {
return $this->callback;
}
public function set_id($id) {
$this->id = $id;
}
public function get_id() {
return $this->id;
}
public function set_post_types($post_types) {
if(!is_array($post_types)) {
$post_types = array($post_types);
}
$this->post_types = $post_types;
}
public function get_post_types() {
return $this->post_types;
}
public function add_post_type($post_type) {
$this->post_types[] = $post_type;
$this->set_post_types(fansub_sanitize_array($this->get_post_types()));
}
public function set_title($title) {
$this->title = $title;
}
public function get_title() {
return $this->title;
}
public function set_fields($fields) {
$this->fields = $fields;
}
public function get_fields() {
return $this->fields;
}
public function add_field($args) {
$callback = fansub_get_value_by_key($args, 'field_callback');
$field_args = isset($args['field_args']) ? $args['field_args'] : $args;
$data_type = fansub_get_value_by_key($args, 'data_type', 'default');
if('fansub_field_datetime_picker' == $callback) {
$this->set_use_datetime_picker(true);
$field_args['type'] = 'datetime';
$args['type'] = 'datetime';
$data_type = 'datetime';
} elseif('fansub_field_color_picker' == $callback) {
$this->set_use_color_picker(true);
} elseif('fansub_field_media_upload' == $callback) {
$this->set_use_media_upload(true);
} elseif('fansub_field_select_chosen' == $callback) {
$this->set_use_select_chosen(true);
}
$this->sanitize_field_args($field_args);
if(isset($args['options'])) {
$field_args['options'] = $args['options'];
}
if($this->get_type() != 'post' && !isset($field_args['label']) && isset($field_args['title'])) {
$field_args['label'] = $field_args['title'];
}
$field_args['data_type'] = $data_type;
$args['field_args'] = $field_args;
$this->fields[] = $args;
}
public function set_type($type) {
$this->type = $type;
}
public function get_type() {
return $this->type;
}
public function __construct($type) {
$this->set_type($type);
$this->set_post_types(array());
$this->set_taxonomies(array());
$this->set_fields(array());
$this->set_title(__('Extra information', 'fansub'));
$this->set_id('fansub_custom_meta');
$this->set_context('normal');
$this->set_priority('high');
}
public function init() {
if($this->is_term_meta()) {
$this->term_meta_init();
} elseif($this->is_menu_item_meta()) {
$this->menu_item_meta_init();
} else {
$this->post_meta_box_init();
}
}
public function add_custom_menu_item_meta_field($item, $args, $depth) {
echo '<div class="fansub-custom-fields menu-item-fields">';
if(fansub_callback_exists($this->get_callback())) {
call_user_func($this->get_callback());
} else {
$menu_id = $item->ID;
foreach($this->get_fields() as $field) {
$field_args = isset($field['field_args']) ? $field['field_args'] : array();
$callback = isset($field['field_callback']) ? $field['field_callback'] : 'fansub_field_input';
$id = fansub_get_value_by_key($field_args, 'id');
$name = fansub_get_value_by_key($field_args, 'name');
$data = $this->build_menu_item_field_data($name, $menu_id);
$field_args['id'] = $data['id'];
$field_args['name'] = $data['name'];
$field_args['class'] = $data['class'];
if(!isset($field_args['value'])) {
$field_args['value'] = $item->{$name};
}
if(fansub_callback_exists($callback)) {
call_user_func($callback, $field_args);
} else {
echo '<p>' . sprintf(__('The callback function %s does not exists!', 'fansub'), '<strong>' . $callback . '</strong>') . '</p>';
}
}
}
echo '</div>';
}
public function load_style_and_script() {
if($this->get_use_media_upload()) {
add_filter('fansub_wp_enqueue_media', '__return_true');
}
if($this->get_use_color_picker()) {
add_filter('fansub_use_color_picker', '__return_true');
}
if($this->get_use_datetime_picker()) {
add_filter('fansub_admin_jquery_datetime_picker', '__return_true');
}
if($this->get_use_select_chosen()) {
add_filter('fansub_use_chosen_select', '__return_true');
}
}
public function add_menu_item_meta($menu_item) {
foreach($this->get_fields() as $field) {
$name = $field['field_args']['name'];
$menu_item->{$name} = fansub_get_post_meta($this->build_menu_item_meta_key($name), $menu_item->ID);
}
return $menu_item;
}
public function build_menu_item_meta_key($key_name) {
$key_name = str_replace('-', '_', $key_name);
return '_menu_item_' . $key_name;
}
public function menu_item_meta_init() {
global $pagenow;
$this->load_style_and_script();
if('nav-menus.php' == $pagenow) {
add_filter('fansub_use_admin_style_and_script', '__return_true');
}
add_filter('wp_setup_nav_menu_item', array($this, 'setup_nav_menu_item'));
add_action('wp_update_nav_menu_item', array($this, 'update_nav_menu_item'), 10, 3);
add_filter('wp_edit_nav_menu_walker', array($this, 'edit_nav_menu_walker'), 10, 2);
add_action('fansub_edit_menu_item_field', array($this, 'add_custom_menu_item_meta_field'), 10, 3);
add_filter('fansub_setup_nav_menu_item', array($this, 'add_menu_item_meta'));
}
public function setup_nav_menu_item($menu_item) {
$menu_item = apply_filters('fansub_setup_nav_menu_item', $menu_item);
return $menu_item;
}
public function update_nav_menu_item($menu_id, $menu_item_db_id, $args) {
do_action('fansub_update_nav_menu_item', $menu_id, $menu_item_db_id, $args);
foreach($this->get_fields() as $field) {
$name = $field['field_args']['name'];
$this->update_menu_item_meta_on_save($name, $menu_item_db_id);
}
}
public function update_menu_item_meta_on_save($field_name, $menu_item_db_id) {
$field_name = str_replace('_', '-', $field_name);
$key = 'menu-item-' . $field_name;
if(isset($_REQUEST[$key]) && is_array($_REQUEST[$key])) {
$value = $_REQUEST[$key][$menu_item_db_id];
update_post_meta($menu_item_db_id, $this->build_menu_item_meta_key($field_name), $value);
}
}
function edit_nav_menu_walker($walker, $menu_id) {
$walker = apply_filters('fansub_edit_nav_menu_walker', 'FANSUB_Menu_Edit_Walker', $menu_id);
return $walker;
}
public function build_menu_item_field_id($field_name, $item_id) {
$id = str_replace('_', '-', $field_name);
return 'edit-menu-item-' . $id . '-' . $item_id;
}
public function build_menu_item_field_name($field_name, $item_id) {
$name = str_replace('_', '-', $field_name);
return 'menu-item-' . $name . '[' . $item_id . ']';
}
public function build_menu_item_field_class($field_name) {
$field_name = str_replace('_', '-', $field_name);
return 'edit-menu-item-' . $field_name;
}
public function build_menu_item_field_data($field_name, $item_id) {
$result = array(
'id' => $this->build_menu_item_field_id($field_name, $item_id),
'name' => $this->build_menu_item_field_name($field_name, $item_id),
'class' => $this->build_menu_item_field_class($field_name)
);
return $result;
}
public function term_meta_init() {
global $pagenow;
$this->load_style_and_script();
if('edit-tags.php' == $pagenow || 'term.php' == $pagenow) {
add_filter('fansub_use_admin_style_and_script', '__return_true');
}
foreach($this->get_taxonomies() as $taxonomy) {
add_action($taxonomy . '_add_form_fields', array($this, 'term_field_add_page'));
add_action($taxonomy . '_edit_form_fields', array($this, 'term_field_edit_page'));
add_action('edited_' . $taxonomy, array($this, 'save_term_data'));
add_action('created_' . $taxonomy, array($this, 'save_term_data'));
}
}
public function term_field_add_page($taxonomy) {
if(fansub_callback_exists($this->get_add_callback())) {
call_user_func($this->get_add_callback(), $taxonomy);
} else {
foreach($this->get_fields() as $field) {
$on_add_page = isset($field['on_add_page']) ? $field['on_add_page'] : false;
if($on_add_page) {
$callback = isset($field['field_callback']) ? $field['field_callback'] : 'fansub_field_input';
if(fansub_callback_exists($callback)) {
$field_args = isset($field['field_args']) ? $field['field_args'] : array();
$id = isset($field_args['id']) ? $field_args['id'] : '';
$name = isset($field_args['name']) ? $field_args['name'] : '';
fansub_transmit_id_and_name($id, $name);
$class = 'term-' . $name . '-wrap';
$class = fansub_sanitize_file_name($class);
fansub_add_string_with_space_before($class, 'form-field fansub');
?>
<div class="<?php echo $class; ?>">
<?php call_user_func($callback, $field_args); ?>
</div>
<?php
}
}
}
}
}
public function term_field_edit_page($term) {
if(fansub_callback_exists($this->get_edit_callback())) {
call_user_func($this->get_edit_callback(), $term);
} else {
$term_id = $term->term_id;
foreach($this->get_fields() as $field) {
$field_args = isset($field['field_args']) ? $field['field_args'] : array();
$callback = isset($field['field_callback']) ? $field['field_callback'] : 'fansub_field_input';
$label = fansub_get_value_by_key($field_args, 'title', fansub_get_value_by_key($field_args, 'label'));
if('fansub_field_input_checkbox' != $callback && 'fansub_field_input_radio' != $callback) {
unset($field_args['label']);
}
$id = isset($field_args['id']) ? $field_args['id'] : '';
$name = isset($field_args['name']) ? $field_args['name'] : '';
fansub_transmit_id_and_name($id, $name);
if(!isset($field_args['value'])) {
$value = fansub_term_get_meta($term_id, $name);
if(empty($value) && 'fansub_field_input_radio' == $callback) {
$value = fansub_get_value_by_key($field, 'default');
}
$field_args['value'] = $value;
}
$class = 'term-' . $name . '-wrap';
$class = fansub_sanitize_file_name($class);
fansub_add_string_with_space_before($class, 'form-field fansub');
?>
<tr class="<?php echo $class; ?>">
<th scope="row"><label for="<?php echo esc_attr(fansub_sanitize_id($id)); ?>"><?php echo $label; ?></label></th>
<td>
<?php
if(fansub_callback_exists($callback)) {
call_user_func($callback, $field_args);
} else {
_e('Please set a valid callback for this field', 'fansub');
}
?>
</td>
</tr>
<?php
}
}
}
public function save_term_data($term_id) {
$fields = $this->get_fields();
foreach($fields as $field) {
$type = isset($field['type']) ? $field['type'] : 'default';
$name = isset($field['field_args']['name']) ? $field['field_args']['name'] : '';
if(empty($name)) {
continue;
}
$value = fansub_sanitize_form_post($name, $type);
fansub_term_update_meta($term_id, $name, $value);
}
return $term_id;
}
public function sanitize_field_args(&$args) {
$id = isset($args['id']) ? $args['id'] : '';
$name = isset($args['name']) ? $args['name'] : '';
fansub_transmit_id_and_name($id, $name);
$args['id'] = $id;
$args['name'] = $name;
if($this->is_term_meta()) {
} elseif($this->is_menu_item_meta()) {
$args['before'] = '<div class="field-' . fansub_sanitize_html_class($name) . ' description description-wide">';
$args['after'] = '</div>';
} else {
$args['before'] = '<div class="meta-row">';
$args['after'] = '</div>';
}
return $args;
}
public function is_term_meta() {
if('term' == $this->get_type()) {
return true;
}
return false;
}
public function is_menu_item_meta() {
if('menu_item' == $this->get_type()) {
return true;
}
return false;
}
public function post_meta_box_init() {
global $pagenow;
$this->load_style_and_script();
if('post-new.php' == $pagenow || 'post.php' == $pagenow || $this->get_use_media_upload()) {
add_filter('fansub_use_admin_style_and_script', '__return_true');
}
add_action('add_meta_boxes', array($this, 'add_meta_box'));
add_action('save_post', array($this, 'save_post'));
}
public function add_meta_box() {
$post_type = fansub_get_current_post_type();
if(in_array($post_type, $this->get_post_types())) {
add_meta_box($this->get_id(), $this->get_title(), array($this, 'post_meta_box_callback'), $post_type, $this->get_context(), $this->get_priority(), $this->get_callback_args());
}
}
public function post_meta_box_callback() {
$class = 'fansub-meta-box';
fansub_add_string_with_space_before($class, $this->get_context());
fansub_add_string_with_space_before($class, $this->get_priority());
foreach($this->get_post_types() as $post_type) {
fansub_add_string_with_space_before($class, 'post-type-' . $post_type);
}
?>
<div class="<?php echo $class; ?>">
<?php
if(fansub_callback_exists($this->get_callback())) {
call_user_func($this->get_callback());
} else {
global $post;
$post_id = $post->ID;
foreach($this->get_fields() as $field) {
$field_args = isset($field['field_args']) ? $field['field_args'] : array();
$callback = isset($field['field_callback']) ? $field['field_callback'] : 'fansub_field_input';
if(!isset($field_args['value'])) {
$field_args['value'] = get_post_meta($post_id, $field_args['name'], true);
}
if(fansub_callback_exists($callback)) {
call_user_func($callback, $field_args);
} else {
echo '<p>' . sprintf(__('The callback function %s does not exists!', 'fansub'), '<strong>' . $callback . '</strong>') . '</p>';
}
}
}
do_action('fansub_post_meta_box_field', $this);
$current_post_type = fansub_get_current_post_type();
if(!empty($current_post_type)) {
do_action('fansub_' . $current_post_type . '_meta_box_field');
}
do_action('fansub_meta_box_' . $this->get_id() . '_field');
?>
</div>
<?php
}
public function save_post($post_id) {
if(!fansub_can_save_post($post_id)) {
return $post_id;
}
foreach($this->get_fields() as $field) {
$type = isset($field['type']) ? $field['type'] : fansub_get_value_by_key($field, 'data_type', 'default');
$name = isset($field['field_args']['name']) ? $field['field_args']['name'] : '';
if(empty($name)) {
continue;
}
$value = fansub_sanitize_form_post($name, $type);
update_post_meta($post_id, $name, $value);
$names = fansub_get_value_by_key($field, 'names');
if(fansub_array_has_value($names)) {
$names = array_combine($names, $names);
foreach($names as $child_name => $child) {
$type = fansub_get_value_by_key($child, 'type', fansub_get_value_by_key($field, 'data_type', 'default'));
$value = fansub_sanitize_form_post($child_name, $type);
update_post_meta($post_id, $child_name, $value);
}
}
}
return $post_id;
}
}

View File

@ -0,0 +1,92 @@
<?php
if(!function_exists('add_filter')) exit;
class FANSUB_MO extends MO {
protected $post_id;
public function __construct($post_id = null) {
if(!post_type_exists('fansub_mo')) {
$this->register_post_type();
}
$this->post_id = $post_id;
}
public function register_post_type() {
$args = array(
'name' => __('String Translation', 'fansub'),
'slug' => 'fansub_mo'
);
fansub_register_post_type_private($args);
}
public function get_object($string, $encrypted = false) {
$post = get_post($this->get_id($string, $encrypted));
if(is_a($post, 'WP_Post') && 'fansub_mo' == $post->post_type) {
return $post;
}
return null;
}
public function export_to_db($string, $translation = '') {
$encrypted_string = md5($string);
$query = fansub_get_post_by_meta('encrypted_string', $encrypted_string);
$post_id = $this->post_id;
$post_title = $this->build_post_title($string);
$postarr = array(
'post_content' => $translation,
'post_type' => 'fansub_mo',
'post_title' => $post_title,
'post_status' => 'private',
'post_excerpt' => $string
);
if(!$query->have_posts()) {
if(fansub_id_number_valid($post_id)) {
$postarr['ID'] = $post_id;
} else {
$mo = $this->get_object($string);
if(is_a($mo, 'WP_Post')) {
$postarr['ID'] = $mo->ID;
}
}
} else {
if(fansub_id_number_valid($this->post_id)) {
$postarr['ID'] = $this->post_id;
}
}
$post_id = fansub_insert_post($postarr);
if(fansub_id_number_valid($post_id)) {
update_post_meta($post_id, 'encrypted_string', $encrypted_string);
}
return $post_id;
}
public function import_from_db($string) {
$translation = '';
if(!empty($string)) {
$post = $this->get_object($string);
if(is_a($post, 'WP_Post')) {
$translation = $post->post_content;
}
}
return $translation;
}
public function delete_from_db($string, $encrypted = false) {
$post = $this->get_object($string, $encrypted);
if(is_a($post, 'WP_Post')) {
wp_delete_post($post->ID, true);
}
}
private function build_post_title($string, $encrypted = false) {
if(!$encrypted) {
$string = md5($string);
}
return 'fansub_mo_' . $string;
}
public function get_id($string, $encrypted = false) {
$string = $this->build_post_title($string, $encrypted);
global $wpdb;
return $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type = %s", $string, 'fansub_mo'));
}
}

View File

@ -0,0 +1,852 @@
<?php
if(!function_exists('add_filter')) exit;
class HOCWP_Option {
private $menu_title;
private $page_title;
private $menu_slug;
private $heading_text;
private $is_option_page;
private $page_title_action;
private $page_header_callback;
private $page_footer_callback;
private $page_sidebar_callback;
private $disable_sidebar;
private $capability;
private $parent_slug;
private $function;
private $icon_url;
private $position;
private $option_group;
private $option_name;
private $sanitize_callback;
private $section_id;
private $section_title;
private $section_callback;
private $section_description;
private $fields;
private $sections;
private $help_tabs;
private $help_sidebar;
private $use_style_and_script;
private $use_media_upload;
private $use_color_picker;
private $use_jquery_ui;
private $use_jquery_ui_sortable;
private $exists;
private $page;
private $update_option;
private $parse_options;
public function disable_sidebar() {
$this->disable_sidebar = true;
}
public function set_parse_options($bool) {
$this->parse_options = $bool;
}
public function get_parse_options() {
return (bool)$this->parse_options;
}
public function set_update_option($bool) {
$this->update_option = $bool;
}
public function get_update_option() {
return (bool)$this->update_option;
}
public function set_page($page) {
$this->page = $page;
}
public function get_page() {
return $this->page;
}
public function set_exists($exists) {
$this->exists = $exists;
}
public function get_exists() {
return $this->exists;
}
public function set_use_style_and_script($use) {
$this->use_style_and_script = $use;
}
public function get_use_style_and_script() {
return (bool)$this->use_style_and_script;
}
public function set_use_jquery_ui_sortable($use) {
$this->use_jquery_ui_sortable = $use;
}
public function get_use_jquery_ui_sortable() {
return $this->use_jquery_ui_sortable;
}
public function set_use_jquery_ui($use) {
$this->use_jquery_ui = $use;
}
public function get_use_jquery_ui() {
return (bool)$this->use_jquery_ui;
}
public function set_use_media_upload($use) {
$this->use_media_upload = $use;
if($use) {
$this->set_use_style_and_script(true);
}
}
public function get_use_media_upload() {
return (bool)$this->use_media_upload;
}
public function set_use_color_picker($use) {
$this->use_color_picker = $use;
}
public function get_use_color_picker() {
return (bool)$this->use_color_picker;
}
public function set_help_sidebar($help_sidebar) {
$this->help_sidebar = $help_sidebar;
}
public function get_help_sidebar() {
return $this->help_sidebar;
}
public function set_help_tabs($help_tabs) {
$this->help_tabs = $help_tabs;
}
public function get_help_tabs() {
return $this->help_tabs;
}
public function set_section_description($section_description) {
$this->section_description = $section_description;
}
public function get_section_description() {
return $this->section_description;
}
public function set_fields($fields) {
$this->fields = $fields;
}
public function get_fields() {
return $this->fields;
}
public function set_sections($sections) {
$this->sections = $sections;
}
public function get_sections() {
return $this->sections;
}
public function set_section_callback($section_callback) {
$this->section_callback = $section_callback;
}
public function get_section_callback() {
if(!fansub_callback_exists($this->section_callback)) {
$this->set_section_callback(array($this, 'default_section_callback'));
}
return $this->section_callback;
}
public function set_section_id($section_id) {
$this->section_id = $section_id;
}
public function get_section_id() {
return $this->section_id;
}
public function set_section_title($section_title) {
$this->section_title = $section_title;
}
public function get_section_title() {
return $this->section_title;
}
public function set_sanitize_callback($sanitize_callback) {
$this->sanitize_callback = $sanitize_callback;
}
public function get_sanitize_callback() {
return $this->sanitize_callback;
}
public function set_option_name($option_name) {
$this->option_name = $option_name;
}
public function get_option_name() {
if(empty($this->option_name)) {
$this->option_name = $this->get_menu_slug();
}
return $this->option_name;
}
public function get_option_name_no_prefix() {
$option_name = $this->get_option_name();
$option_name = str_replace('fansub_', '', $option_name);
return $option_name;
}
public function set_option_group($option_group) {
$this->option_group = $option_group;
}
public function get_option_group() {
if(empty($this->option_group)) {
$this->option_group = $this->get_menu_slug();
}
return $this->option_group;
}
public function set_menu_title($menu_title) {
$this->menu_title = $menu_title;
}
public function get_menu_title() {
return $this->menu_title;
}
public function get_heading_text() {
return $this->heading_text;
}
public function set_heading_text($text) {
$this->heading_text = $text;
}
public function get_page_title_action() {
return $this->page_title_action;
}
public function set_page_title_action($action, $url, $text) {
$action = fansub_sanitize($action, 'html_class');
fansub_add_string_with_space_before($action, 'page-title-action');
$link = new HOCWP_HTML('a');
$link->set_class($action);
$link->set_attribute('href', $url);
$link->set_text($text);
$this->page_title_action = $link->build();
}
public function set_page_sidebar_callback($func) {
$this->page_sidebar_callback = $func;
}
public function get_page_sidebar_callback() {
return $this->page_sidebar_callback;
}
public function set_page_header_callback($func) {
$this->page_header_callback = $func;
}
public function get_page_header_callback() {
return $this->page_header_callback;
}
public function set_page_footer_callback($func) {
$this->page_footer_callback = $func;
}
public function get_page_footer_callback() {
return $this->page_footer_callback;
}
public function is_option_page() {
return (bool)$this->is_option_page;
}
public function set_is_option_page($value) {
$this->is_option_page = $value;
}
public function set_menu_slug($menu_slug) {
$this->menu_slug = $menu_slug;
}
public function get_menu_slug() {
return $this->menu_slug;
}
public function set_page_title($page_title) {
$this->page_title = $page_title;
}
public function get_page_title() {
return $this->page_title;
}
public function set_capability($capability) {
$this->capability = $capability;
}
public function get_capability() {
return $this->capability;
}
public function set_parent_slug($parent_slug) {
$this->parent_slug = $parent_slug;
}
public function get_parent_slug() {
return $this->parent_slug;
}
public function set_function($function) {
$this->function = $function;
}
public function get_function() {
if(!fansub_callback_exists($this->function)) {
$this->function = array($this, 'default_setting_page_callback');
}
return $this->function;
}
public function set_icon_url($icon_url) {
$this->icon_url = $icon_url;
}
public function get_icon_url() {
return $this->icon_url;
}
public function set_position($position) {
$this->position = $position;
}
public function get_position() {
return $this->position;
}
public function __construct($menu_title, $menu_slug) {
$this->set_menu_title($menu_title);
$this->set_page_title($menu_title);
$this->set_heading_text($menu_title);
$this->set_menu_slug($menu_slug);
$this->set_is_option_page(true);
$this->set_sanitize_callback(array($this, 'sanitize'));
$this->set_capability('manage_options');
$this->set_use_style_and_script(true);
$this->set_parent_slug('options-general.php');
$this->set_section_id('default');
$this->set_section_title('');
$this->set_sections(array());
$this->set_fields(array());
$this->set_help_tabs(array());
if(empty($menu_title)) {
$this->set_exists(true);
}
if($this->get_exists()) {
$this->set_option_name('fansub_' . fansub_sanitize_id($menu_slug));
}
}
public function settings_saved() {
$option_name = $this->get_option_name();
if(isset($_POST[$option_name])) {
$old = (array)get_option($option_name);
$new = (array)$_POST[$option_name];
$new = wp_parse_args($new, $old);
update_option($option_name, $new);
}
}
public function is_this_page() {
global $pagenow;
$page = fansub_get_current_admin_page();
if($page == $this->get_menu_slug()) {
if(($this->is_submenu() && $pagenow == $this->get_parent_slug()) || 'admin.php' == $pagenow) {
return true;
}
} elseif($pagenow == $this->get_page()) {
return true;
}
return false;
}
public function form() {
?>
<form novalidate="novalidate" action="options.php" method="post">
<?php
settings_fields($this->get_option_group());
do_settings_sections($this->get_menu_slug());
submit_button();
?>
</form>
<?php
}
public function default_setting_page_callback() {
$parent_slug = $this->get_parent_slug();
if(empty($parent_slug)) {
return;
}
$disable_sidebar = (bool)$this->disable_sidebar;
$title = $this->get_heading_text();
if($this->is_option_page() && !fansub_string_contain(strtolower($title), 'settings') && !fansub_string_contain(strtolower($title), 'options')) {
fansub_add_string_with_space_before($title, 'Settings');
}
$wrap_class = $this->get_option_name_no_prefix();
$wrap_class = fansub_sanitize($wrap_class, 'html_class');
fansub_add_string_with_space_before($wrap_class, 'wrap fansub option-page');
if(!$disable_sidebar) {
fansub_add_string_with_space_before($wrap_class, 'has-sidebar');
}
?>
<div class="<?php echo $wrap_class; ?>">
<h1 class="page-title"><?php echo esc_html($title). $this->get_page_title_action(); ?></h1>
<?php
$header_callback = $this->get_page_header_callback();
if(fansub_callback_exists($header_callback)) {
call_user_func($header_callback);
}
$page_content_class = 'page-content';
if($disable_sidebar) {
fansub_add_string_with_space_before($page_content_class, 'no-sidebar');
}
?>
<div class="<?php echo $page_content_class; ?>">
<?php
if((bool)$this->disable_sidebar) {
if($this->is_option_page()) {
if($this->is_this_page() && (isset($_REQUEST['submit']) || isset($_REQUEST['settings-updated']))) {
do_action('fansub_option_saved');
if('options-general.php' != $this->get_parent_slug() && !$this->get_exists()) {
fansub_admin_notice_setting_saved();
}
do_action($this->get_menu_slug() . '_option_saved', $this);
}
$this->form();
}
do_action('fansub_option_page_content');
do_action('fansub_option_page_' . $this->get_option_name_no_prefix() . '_content');
} else {
?>
<div class="sidebar">
<?php
$sidebar_callback = $this->get_page_sidebar_callback();
if(fansub_callback_exists($sidebar_callback)) {
call_user_func($sidebar_callback);
}
?>
</div>
<div class="main main-content">
<?php
if($this->is_option_page()) {
if($this->is_this_page() && (isset($_REQUEST['submit']) || isset($_REQUEST['settings-updated']))) {
do_action('fansub_option_saved');
if('options-general.php' != $this->get_parent_slug() && !$this->get_exists()) {
fansub_admin_notice_setting_saved();
}
do_action($this->get_menu_slug() . '_option_saved', $this);
}
$this->form();
}
do_action('fansub_option_page_content');
do_action('fansub_option_page_' . $this->get_option_name_no_prefix() . '_content');
?>
</div>
<?php
}
?>
</div>
<?php
$footer_callback = $this->get_page_footer_callback();
if(fansub_callback_exists($footer_callback)) {
call_user_func($footer_callback);
}
?>
</div>
<?php
}
public function add_option_tab(&$option_tabs) {
$option_tabs = fansub_sanitize_array($option_tabs);
$option_tabs[$this->get_option_name()] = array(
'text' => $this->get_menu_title(),
);
}
public function init() {
if($this->get_exists()) {
$this->exists_page_init();
} else {
add_action('admin_menu', array($this, 'menu_init'));
add_action('admin_init', array($this, 'setting_init'));
if($this->is_this_page()) {
add_action('admin_head', array($this, 'help_tab_init'));
add_action('admin_enqueue_scripts', array($this, 'enqueue_style_and_script'));
}
}
if($this->get_update_option()) {
$this->settings_saved();
}
}
public function enqueue_style_and_script() {
if($this->get_use_style_and_script()) {
add_filter('fansub_use_admin_style_and_script', '__return_true');
}
if($this->get_use_color_picker()) {
add_filter('fansub_use_color_picker', '__return_true');
}
if($this->get_use_media_upload()) {
add_filter('fansub_wp_enqueue_media', '__return_true');
}
if($this->get_use_jquery_ui()) {
add_filter('fansub_use_jquery_ui', '__return_true');
}
if($this->get_use_jquery_ui_sortable()) {
add_filter('fansub_use_jquery_ui_sortable', '__return_true');
}
if(!fansub_is_my_theme()) {
add_action('admin_print_scripts', 'fansub_admin_enqueue_scripts');
}
}
public function help_tab_init() {
$current_screen = get_current_screen();
foreach($this->get_help_tabs() as $args) {
$current_screen->add_help_tab($args);
}
$help_sidebar = $this->get_help_sidebar();
$current_screen->set_help_sidebar($help_sidebar);
}
public function setting_init() {
$this->register_setting();
$this->section_init();
$this->field_init();
}
public function exists_page_init() {
add_action('admin_init', array($this, 'exists_setting_page_field'));
}
public function exists_setting_page_field() {
$this->setting_init();
}
private function section_init() {
if(!$this->get_exists()) {
$this->add_settings_section_default();
}
foreach($this->get_sections() as $args) {
$id = isset($args['id']) ? $args['id'] : '';
$title = isset($args['title']) ? $args['title'] : '';
$callback = isset($args['callback']) ? $args['callback'] : '';
if(!fansub_callback_exists($callback)) {
$callback = array($this, 'default_section_callback');
}
$this->add_settings_section($id, $title, $callback);
}
}
public function section_description($text) {
$p = new HOCWP_HTML('p');
$p->set_text($text);
$p->output();
}
public function sanitize($input) {
$fields = $this->get_fields();
if(fansub_array_has_value($fields)) {
foreach($fields as $field) {
$data_type = fansub_get_value_by_key($field, 'data_type');
if('checkbox' == $data_type) {
$name = fansub_get_value_by_key($field, 'name');
if(!empty($name)) {
$input[$name] = fansub_checkbox_post_data_value($input, $name);
}
}
}
}
if($this->get_parse_options()) {
$old = (array)get_option($this->get_option_name());
$input = (array)$input;
$input = wp_parse_args($input, $old);
}
$input = apply_filters('fansub_sanitize_option_' . $this->get_option_name_no_prefix(), $input);
do_action('fansub_sanitize_' . $this->get_option_name_no_prefix() . '_option', $input);
$input = apply_filters('validate_options', $input);
return apply_filters('fansub_validate_options', $input);
}
public function field_init() {
foreach($this->get_fields() as $args) {
$id = isset($args['id']) ? $args['id'] : '';
$title = isset($args['title']) ? $args['title'] : '';
$callback = isset($args['callback']) ? $args['callback'] : '';
$section = isset($args['section']) ? $args['section'] : $this->get_section_id();
if(!fansub_callback_exists($callback)) {
$callback = array($this, 'default_field_callback');
}
if($this->get_exists()) {
$class = isset($args['class']) ? $args['class'] : '';
fansub_add_string_with_space_before($class, 'fansub');
$args['class'] = $class;
}
$this->add_settings_field($id, $title, $callback, $section, $args);
}
}
public function default_field_callback($args) {
$callback = isset($args['field_callback']) ? $args['field_callback'] : 'fansub_field_input';
if(fansub_callback_exists($callback)) {
$name = isset($args['name']) ? fansub_sanitize_array($args['name']) : array();
if(!fansub_array_has_value($name)) {
$name = isset($args['id']) ? fansub_sanitize_array($args['id']) : array();
}
if(!fansub_array_has_value($name)) {
_e('Please set name for this field.', 'fansub');
return;
}
$base_name = $name;
unset($args['class']);
if(!isset($args['value'])) {
$value = $this->get_by_key($name, fansub_get_value_by_key($args, 'default'));
if(is_array($value) && 'fansub_field_input' == $callback) {
$value = '';
}
$args['value'] = $value;
}
if('fansub_field_size' == $callback || 'fansub_field_input_size' == $callback) {
$tmp_name = $name;
$tmp_name[] = 'width';
$args['name_width'] = $this->get_field_name($tmp_name);
$args['id_width'] = $this->get_field_id($tmp_name);
$tmp_name = $name;
$tmp_name[] = 'height';
$args['name_height'] = $this->get_field_name($tmp_name);
$args['id_height'] = $this->get_field_id($tmp_name);
$tmp_sizes = $this->get_by_key($name, fansub_get_value_by_key($args, 'default'));
$sizes = array();
}
$args['name'] = $this->get_field_name($name);
$args['id'] = $this->get_field_id($name);
$options = isset($args['options']) ? $args['options'] : array();
if(fansub_array_has_value($options)) {
$tmp_options = array();
foreach($options as $option) {
$name = isset($option['name']) ? fansub_sanitize_array($option['name']) : array();
if(!fansub_array_has_value($name)) {
if(!empty($base_name)) {
$name = fansub_sanitize_array($base_name);
} else {
$name = isset($option['id']) ? fansub_sanitize_array($option['id']) : array();
}
}
if(!fansub_array_has_value($name)) {
continue;
}
if(!isset($option['value'])) {
$value = $this->get_by_key($name, fansub_get_value_by_key($option, 'default'));
if(is_array($value) && 'fansub_field_input' == $callback) {
$value = '';
}
$option['value'] = $value;
}
$option['name'] = $this->get_field_name($name);
$option['id'] = $this->get_field_id($name);
$tmp_options[] = $option;
}
$args['options'] = $tmp_options;
unset($tmp_options);
}
call_user_func($callback, $args);
} else {
_e('Please set a valid callback for this field.', 'fansub');
}
}
public function get() {
return get_option($this->get_option_name());
}
public function get_page_url() {
$url = '';
if($this->is_submenu() && strrpos($this->get_parent_slug(), '.php') !== false) {
$url .= $this->get_parent_slug();
} else {
$url .= 'admin.php';
}
$url .= '?page=' . $this->get_menu_slug();
return admin_url($url);
}
public function get_by_key($key, $default = '') {
$result = '';
$options = $this->get();
if(is_array($options)) {
$result = fansub_get_value_by_key($options, $key, $default);
} elseif('' != $options) {
$result = $options;
}
return $result;
}
public function get_field_name($field_name) {
return fansub_sanitize_field_name($this->get_option_name(), $field_name);
}
public function get_field_id($field_id) {
$id = $this->get_field_name($field_id);
$id = fansub_sanitize_id($id);
return $id;
}
private function get_section_by_id($id) {
$section = array();
$sections = $this->get_sections();
foreach($sections as $args) {
$section_id = isset($args['id']) ? $args['id'] : '';
if($id == $section_id) {
$section = $args;
break;
}
}
return $section;
}
public function default_section_callback($args) {
$id = isset($args['id']) ? $args['id'] : '';
$description = '';
if($id == $this->get_section_id()) {
$description = $this->get_section_description();
} else {
$section = $this->get_section_by_id($id);
$description = isset($section['description']) ? $section['description'] : '';
}
if(!empty($description)) {
$this->section_description($description);
}
}
public function is_submenu() {
$menu_parent = $this->get_parent_slug();
if(!empty($menu_parent) && 'admin.php' != $menu_parent) {
return true;
}
return false;
}
public function menu_init() {
if($this->is_submenu()) {
$this->add_submenu_page();
} else {
$this->add_menu_page();
}
}
public function add_menu_page() {
add_menu_page($this->get_page_title(), $this->get_menu_title(), $this->get_capability(), $this->get_menu_slug(), $this->get_function(), $this->get_icon_url(), $this->get_position());
}
public function add_submenu_page() {
add_submenu_page($this->get_parent_slug(), $this->get_page_title(), $this->get_menu_title(), $this->get_capability(), $this->get_menu_slug(), $this->get_function());
}
public function register_setting() {
register_setting($this->get_option_group(), $this->get_option_name(), $this->get_sanitize_callback());
}
public function add_settings_section($id, $title, $callback) {
if(!$this->section_exists($id)) {
add_settings_section($id, $title, $callback, $this->get_menu_slug());
}
}
public function section_exists($section) {
global $wp_settings_sections;
if(isset($wp_settings_sections[$this->get_menu_slug()][$section])) {
return true;
}
return false;
}
public function add_settings_section_default() {
$this->add_settings_section($this->get_section_id(), $this->get_section_title(), $this->get_section_callback());
}
public function add_section($args = array()) {
$this->sections[] = $args;
}
private function add_settings_field($id, $title, $callback, $section = 'default', $args = array()) {
if(!$this->field_exists($section, $id)) {
add_settings_field($id, $title, $callback, $this->get_menu_slug(), $section, $args);
}
}
public function field_exists($section, $field) {
global $wp_settings_fields;
if(isset($wp_settings_fields[$this->get_menu_slug()][$section][$field])) {
return true;
}
return false;
}
public function add_field($args = array()) {
$data_type = fansub_get_value_by_key($args, 'data_type', 'default');
$callback = fansub_get_value_by_key($args, 'field_callback');
if(fansub_callback_exists($callback)) {
if('fansub_field_input_checkbox' == $callback) {
$data_type = 'checkbox';
} elseif('fansub_field_color_picker' == $callback) {
$this->set_use_color_picker(true);
}
}
$args['data_type'] = $data_type;
$id = isset($args['id']) ? $args['id'] : '';
$name = isset($args['name']) ? $args['name'] : '';
$class = isset($args['class']) ? $args['class'] : '';
if(!isset($args['field_class'])) {
$args['field_class'] = $class;
}
fansub_transmit_id_and_name($id, $name);
$args['id'] = $id;
$args['name'] = $name;
$this->fields[] = $args;
}
public function do_settings_fields($section = 'default') {
do_settings_fields($this->get_menu_slug(), $section);
}
public function add_help_tab($args) {
$this->help_tabs[] = $args;
}
}

View File

@ -0,0 +1,234 @@
<?php
if(!function_exists('add_filter')) exit;
class FANSUB_Remove_Term_Base {
private $query_var;
private $query_var_redirect;
private $base;
private $taxonomy;
public function set_taxonomy($taxonomy) {
$this->taxonomy = $taxonomy;
}
public function set_base($base) {
$this->base = $base;
$this->set_query_var($this->taxonomy);
}
public function set_query_var($query_var) {
$this->query_var = $query_var;
$this->set_query_var_redirect($this->query_var . '_redirect');
}
public function set_query_var_redirect($query_var_redirect) {
$this->query_var_redirect = $query_var_redirect;
}
public function __construct($taxonomy) {
$this->set_taxonomy($taxonomy);
$this->base = $this->get_taxonomy_base($taxonomy);
$this->query_var = $this->get_taxonomy_query_var($taxonomy);
$this->query_var_redirect = $this->query_var . '_redirect';
}
public function get_taxonomy_query_var($taxonomy) {
$result = '';
if(taxonomy_exists($taxonomy)) {
$taxonomy = get_taxonomy($taxonomy);
$result = $taxonomy->query_var;
}
return $result;
}
public function get_taxonomy_base($taxonomy = null) {
if(empty($taxonomy)) {
$taxonomy = $this->taxonomy;
}
$base_slug = '';
if(taxonomy_exists($taxonomy)) {
$taxonomy = get_taxonomy($taxonomy);
$base_slug = fansub_get_value_by_key($taxonomy->rewrite, 'slug');
}
return $base_slug;
}
public function add_permastructs() {
$this->extra_permastructs($this->taxonomy, '%' . $this->taxonomy . '%');
}
public function add_query_vars($query_vars) {
return $this->add_query_var($query_vars, $this->query_var_redirect);
}
public function control_request($query_vars) {
$this->control_request_helper($this->taxonomy, $query_vars, $this->query_var_redirect);
return $query_vars;
}
public function term_link($termlink, $term, $taxonomy) {
if($taxonomy == $this->taxonomy) {
if(!empty($this->base)) {
$termlink = str_replace('/' . $this->base . '/', '/' , $termlink);
}
$termlink = apply_filters('fansub_rewrite_term_link', $termlink, $term);
}
return $termlink;
}
public function term_rewrite_rules($rules) {
$rules = $this->add_rewrite_rule($this->taxonomy, $this->get_taxonomy_base(), $this->query_var, $this->query_var_redirect, $rules);
return $rules;
}
public function flush_rewrite_rule() {
flush_rewrite_rules();
}
public function init() {
if(!fansub_pretty_permalinks_enabled()) {
return;
}
if('category' == $this->taxonomy) {
$this->remove_category_base();
} elseif('post_tag' == $this->taxonomy) {
$this->remove_post_tag_base_slug();
} else {
$base = apply_filters('fansub_remove_term_base_taxonomy_base', $this->base, $this->taxonomy);
$this->set_base($base);
if(empty($this->base) || empty($this->query_var)) {
return;
}
add_action('init', array($this, 'add_permastructs'));
add_filter('query_vars', array($this, 'add_query_vars'));
add_filter('request', array($this, 'control_request'));
add_filter($this->taxonomy . '_rewrite_rules', array($this, 'term_rewrite_rules'));
add_filter('term_link', array($this, 'term_link'), 10, 3);
add_action('created_' . $this->taxonomy, array($this, 'flush_rewrite_rule'));
add_action('edited_' . $this->taxonomy, array($this, 'flush_rewrite_rule'));
add_action('delete_' . $this->taxonomy, array($this, 'flush_rewrite_rule'));
}
}
public function get_taxonomy_base_slug($key, $default) {
$saved = get_option($key);
$tax_base = (empty($saved)) ? $default : $saved;
return $tax_base;
}
public function extra_permastructs($taxonomy_name, $tag_struct) {
global $wp_rewrite;
$is_old_wp_version = version_compare($GLOBALS['wp_version'], '3.4', '<');
if($is_old_wp_version) {
$wp_rewrite->extra_permastructs[$taxonomy_name][0] = $tag_struct;
} else {
$wp_rewrite->extra_permastructs[$taxonomy_name]['struct'] = $tag_struct;
}
}
public function add_query_var($query_vars, $query_var) {
$query_vars[] = $query_var;
return $query_vars;
}
public function control_request_helper($taxonomy_name, $query_vars, $query_var) {
if(isset($query_vars[$query_var])) {
$term_name = user_trailingslashit($query_vars[$query_var], $taxonomy_name);
$term_permalink = home_url($term_name);
wp_redirect($term_permalink, 301);
exit;
}
}
public function add_rewrite_rule($taxonomy_name, $tax_base, $wp_query_var, $query_var, $rules) {
$rules = array();
$terms = fansub_get_terms($taxonomy_name, array('hide_empty' => false));
foreach($terms as $term) {
$rules['(' . $term->slug . ')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?' . $wp_query_var . '=$matches[1]&feed=$matches[2]';
$rules['(' . $term->slug . ')/page/?([0-9]{1,})/?$'] = 'index.php?' . $wp_query_var . '=$matches[1]&paged=$matches[2]';
$rules['(' . $term->slug . ')/?$'] = 'index.php?' . $wp_query_var . '=$matches[1]';
}
$tax_base = trim($tax_base, '/');
$rules[$tax_base . '/(.*)$'] = 'index.php?' . $query_var . '=$matches[1]';
return $rules;
}
// Remove category (/category/ into /) base slug from url
public function remove_category_base() {
add_action('init', array($this, 'category_extra_permastructs'));
add_filter('query_vars', array($this, 'category_query_vars'));
add_filter('request', array($this, 'category_request'));
add_filter('category_rewrite_rules', array($this, 'category_rewrite_rules'));
add_filter('category_link', array($this, 'category_link'));
add_action('created_category', array($this, 'flush_rewrite_rule'));
add_action('edited_category', array($this, 'flush_rewrite_rule'));
add_action('delete_category', array($this, 'flush_rewrite_rule'));
}
public function get_category_base() {
return $this->get_taxonomy_base_slug('category_base', 'category');
}
public function category_extra_permastructs() {
$this->extra_permastructs('category', '%category%');
}
public function category_query_vars($public_query_vars) {
return $this->add_query_var($public_query_vars, 'category_redirect');
}
public function category_request($query_vars) {
$this->control_request_helper('category', $query_vars, 'category_redirect');
return $query_vars;
}
public function category_rewrite_rules($rules) {
$rules = $this->add_rewrite_rule('category', $this->get_category_base(), 'category_name', 'category_redirect', $rules);
return $rules;
}
public function category_link($termlink) {
$category_base = $this->get_category_base();
return str_replace('/' . $category_base . '/', '/' , $termlink);
}
// Remove post_tag (/tag/ into /) base slug from url
public function remove_post_tag_base_slug() {
add_action('init', array($this, 'tag_extra_permastructs'));
add_filter('query_vars', array($this, 'tag_query_vars'));
add_filter('request', array($this, 'tag_request'));
add_filter('tag_rewrite_rules', array($this, 'tag_rewrite_rules'));
add_filter('tag_link', array($this, 'tag_link'));
add_action('created_post_tag', array($this, 'flush_rewrite_rule'));
add_action('edited_post_tag', array($this, 'flush_rewrite_rule'));
add_action('delete_post_tag', array($this, 'flush_rewrite_rule'));
}
public function get_tag_base() {
return $this->get_taxonomy_base_slug('tag_base', 'tag');
}
public function tag_extra_permastructs() {
$this->extra_permastructs('post_tag', '%post_tag%');
}
public function tag_query_vars($public_query_vars) {
return $this->add_query_var($public_query_vars, 'tag_redirect');
}
public function tag_request($query_vars) {
$this->control_request_helper('post_tag', $query_vars, 'tag_redirect');
return $query_vars;
}
public function tag_rewrite_rules($rules) {
$rules = $this->add_rewrite_rule('post_tag', $this->get_tag_base(), 'tag', 'tag_redirect', $rules);
return $rules;
}
public function tag_link($termlink) {
$tag_base = $this->get_tag_base();
return str_replace('/' . $tag_base . '/', '/' , $termlink);
}
}

View File

@ -0,0 +1,60 @@
<?php
if(!function_exists('add_filter')) exit;
class FANSUB_Rewrite {
private $taxonomies = array();
private $tax_objects = array();
public function set_taxonomy_objects($tax_objects) {
$this->tax_objects = $tax_objects;
}
public function add_taxonomy_object($tax_object) {
if(fansub_object_valid($tax_object)) {
if(!isset($this->tax_objects[$tax_object->name])) {
$this->tax_objects[$tax_object->name] = $tax_object;
}
}
}
public function get_taxonomy_objects() {
return $this->tax_objects;
}
public function set_taxonomies($taxonomies) {
$this->taxonomies = $taxonomies;
foreach($taxonomies as $taxonomy) {
$this->add_taxonomy_object(get_taxonomy($taxonomy));
}
}
public function add_taxonomy($taxonomy) {
if(!array_search($taxonomy, $this->get_taxonomies())) {
$this->taxonomies[] = $taxonomy;
$this->add_taxonomy_object(get_taxonomy($taxonomy));
}
}
public function get_taxonomies() {
return $this->taxonomies;
}
public function __construct() {
}
public function remove_taxonomy_base() {
$taxonomies = $this->get_taxonomies();
foreach($taxonomies as $taxonomy) {
$remove_base = new FANSUB_Remove_Term_Base($taxonomy);
switch($taxonomy) {
case 'category':
$remove_base->set_base('category');
break;
case 'post_tag':
$remove_base->set_base('tag');
break;
}
$remove_base->init();
}
}
}

View File

@ -0,0 +1,77 @@
<?php
if(!function_exists('add_filter')) exit;
if(defined('FANSUB_SERIAL_VERSION')) {
return;
}
define('FANSUB_SERIAL_VERSION', '1.0.0');
class FANSUB_Serial {
private $characters;
public $amount;
public $pattern;
public $splitter;
public function __construct($pattern = '', $amount = 1, $splitter = '-') {
if(empty($pattern)) {
$pattern = 'XXXXX-XXXXX-XXXXX-XXXXX-XXXXX';
}
$this->set_amount($amount);
$this->set_pattern($pattern);
$this->set_splitter($splitter);
$this->set_characters(fansub_get_safe_captcha_characters());
}
public function set_characters($characters) {
$this->characters = $characters;
}
public function set_amount($amount) {
$this->amount = $amount;
}
public function set_pattern($pattern) {
$pattern = strtoupper($pattern);
$this->pattern = $pattern;
}
public function set_splitter($splitter) {
$this->splitter = $splitter;
}
public function get_characters() {
return $this->characters;
}
public function get_amount() {
return absint($this->amount);
}
public function get_pattern() {
return strtoupper($this->pattern);
}
public function get_splitter() {
return $this->splitter;
}
public function generate() {
$amount = $this->get_amount();
$splitter = $this->get_splitter();
$pattern = $this->get_pattern();
$pieces = explode($splitter, $pattern);
$result = array();
for($i = 0; $i < $amount; $i++) {
$serial = array();
foreach($pieces as $piece) {
$len = strlen($piece);
$item = fansub_random_string($len, $this->get_characters());
$serial[] = $item;
}
$serial = implode($splitter, $serial);
$result[] = strtoupper($serial);
}
if(2 > $amount) {
$result = current($result);
}
return $result;
}
}

View File

@ -0,0 +1,169 @@
<?php
if(!function_exists('add_filter')) exit;
if(!class_exists('WP_List_Table')) {
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
}
class HOCWP_Table_String_Translation extends WP_List_Table {
protected $languages, $strings, $active_strings, $groups, $selected_group;
function __construct() {
parent::__construct(array(
'plural' => 'String Translation',
'ajax' => false
));
$this->languages = fansub_get_qtranslate_x_enabled_languages();
$this->strings = fansub_get_registered_string_language();
$this->active_strings = fansub_get_active_registered_string_language();
if(!is_array($this->active_strings)) {
$this->active_strings = array();
}
$this->groups = array_unique(wp_list_pluck($this->strings, 'context'));
$this->selected_group = empty($_GET['group']) || !in_array($_GET['group'], $this->groups) ? -1 : $_GET['group'];
$this->save_translations();
}
function get_columns() {
$columns = array(
'cb' => '<input type="checkbox">',
'string' => __('String', 'fansub'),
'name' => __('Name', 'fansub'),
'context' => __('Group', 'fansub'),
'translations' => __('Translation', 'fansub'),
);
return $columns;
}
function get_sortable_columns() {
return array(
'string' => array('string', false),
'name' => array('name', false),
'context' => array('context', false),
);
}
protected function usort_reorder($a, $b) {
$result = strcmp($a[$_GET['orderby']], $b[$_GET['orderby']]);
return (empty($_GET['order']) || 'asc' === $_GET['order']) ? $result : -$result;
}
function prepare_items() {
$data = $this->strings;
$active_data = $this->active_strings;
$s = empty($_GET['s']) ? '' : wp_unslash($_GET['s']);
foreach($data as $key => $row) {
if((-1 !== $this->selected_group && $row['context'] !== $this->selected_group) || (!empty($s) && stripos($row['name'], $s) === false && stripos($row['string'], $s) === false)) {
unset($data[$key]);
}
}
$count = 0;
foreach($data as $key => $row) {
$data[$key]['row'] = $count;
$mo = new HOCWP_MO();
$translation = $mo->import_from_db($row['string']);
$data[$key]['translation'] = $translation;
if(!isset($active_data[$key])) {
$data[$key]['bulk_action'] = true;
}
$count++;
}
$per_page = $this->get_items_per_page('fansub_string_translation_posts_per_page');
$this->_column_headers = array($this->get_columns(), array(), $this->get_sortable_columns());
if(!empty($_GET['orderby'])) {
usort($data, array(&$this, 'usort_reorder'));
}
$total_items = count($data);
$this->items = array_slice($data, ($this->get_pagenum() - 1) * $per_page, $per_page);
$this->set_pagination_args(array(
'total_items' => $total_items,
'per_page' => $per_page,
'total_pages' => ceil($total_items / $per_page)
));
}
function get_bulk_actions() {
return array('delete' => __('Delete', 'fansub'));
}
public function current_action() {
return empty($_POST['submit']) ? parent::current_action() : false;
}
function extra_tablenav($which) {
if('top' !== $which) {
return;
}
echo '<div class="alignleft actions">';
printf('<label class="screen-reader-text" for="select-group" >%s</label>', __( 'Filter by group', 'fansub'));
echo '<select id="select-group" name="group">' . "\n";
printf(
'<option value="-1"%s>%s</option>' . "\n",
-1 === $this->group_selected ? ' selected="selected"' : '',
__('View all groups', 'fansub')
);
foreach($this->groups as $group) {
printf(
'<option value="%s"%s>%s</option>' . "\n",
esc_attr(urlencode($group)),
$this->selected_group === $group ? ' selected="selected"' : '',
esc_html($group)
);
}
echo '</select>'."\n";
submit_button(__('Filter'), 'button', 'filter_action', false, array('id' => 'post-query-submit'));
echo '</div>';
}
public function display_tablenav($which) {
?>
<div class="tablenav <?php echo esc_attr($which); ?>">
<?php if($this->has_items()) : ?>
<div class="alignleft actions bulkactions">
<?php $this->bulk_actions($which); ?>
</div>
<?php endif;
$this->extra_tablenav($which);
$this->pagination($which);
?>
<br class="clear">
</div>
<?php
}
public function save_translations() {
}
function column_default($item, $column_name) {
return $item[$column_name];
}
function column_cb($item) {
return sprintf(
'<label class="screen-reader-text" for="cb-select-%1$s">%2$s</label><input id="cb-select-%1$s" type="checkbox" name="strings[]" value="%3$s" %4$s>',
esc_attr(fansub_get_value_by_key($item, 'row')),
sprintf(__('Select %s'), format_to_edit($item['string'])),
md5($item['string']),
empty($item['bulk_action']) ? 'disabled' : ''
);
}
function column_string($item) {
return format_to_edit($item['string']);
}
function column_translations($item) {
$out = '';
$string = fansub_get_value_by_key($item, 'string');
if(!empty($string)) {
$input_type = $item['multiline'] ?
'<textarea name="translation[%1$s]" id="%1$s-%2$s" class="widefat">%3$s</textarea>' :
'<input type="text" name="translation[%1$s]" id="%1$s-%2$s" class="widefat" value="%3$s" />';
$out .= sprintf(
$input_type,
esc_attr(md5($string)),
esc_attr($item['row']),
format_to_edit($item['translation'])
);
}
return $out;
}
}

View File

@ -0,0 +1,16 @@
<?php
if(!function_exists('add_filter')) exit;
class FANSUB_TinyMCE_Shortcode {
public function __construct() {
$mce = new FANSUB_TinyMCE();
$script_url = FANSUB_URL . '/js/fansub-tinymce-shortcode-button' . FANSUB_JS_SUFFIX;
$item_args = array(
'name' => 'fansub_shortcode',
'script' => $script_url,
'type' => 'listbox'
);
$mce->add_item($item_args, 2);
$mce->init();
}
}

View File

@ -0,0 +1,117 @@
<?php
if(!function_exists('add_filter')) exit;
class FANSUB_TinyMCE {
private $mce_buttons;
private $mce_buttons_2;
private $mce_buttons_3;
private $mce_buttons_4;
public function __construct() {
$this->init_properties();
}
public function init() {
add_action('init', array($this, 'init_button'));
}
private function init_properties() {
$this->mce_buttons = array();
$this->mce_buttons_2 = array();
$this->mce_buttons_3 = array();
$this->mce_buttons_4 = array();
}
public function init_button() {
if(!fansub_current_user_can_use_rich_editor()) {
return;
}
add_filter('mce_external_plugins', array($this, 'mce_external_plugins'));
add_filter('mce_buttons', array($this, 'mce_buttons'));
add_filter('mce_buttons_2', array($this, 'mce_buttons_2'));
add_filter('mce_buttons_3', array($this, 'mce_buttons_3'));
add_filter('mce_buttons_4', array($this, 'mce_buttons_4'));
}
public function add_item($args, $toolbar = 1) {
switch($toolbar) {
case 2:
array_push($this->mce_buttons_2, $args);
break;
case 3:
array_push($this->mce_buttons_3, $args);
break;
case 4:
array_push($this->mce_buttons_4, $args);
break;
default:
array_push($this->mce_buttons, $args);
}
}
public function mce_external_plugins($plugin_array) {
$plugin_array = $this->add_mce_button_script($this->mce_buttons, $plugin_array);
$plugin_array = $this->add_mce_button_script($this->mce_buttons_2, $plugin_array);
$plugin_array = $this->add_mce_button_script($this->mce_buttons_3, $plugin_array);
$plugin_array = $this->add_mce_button_script($this->mce_buttons_4, $plugin_array);
return $plugin_array;
}
private function add_mce_plugin_script($plugin_array, $name, $script) {
$plugin_array[$name] = $script;
return $plugin_array;
}
private function add_mce_button_script($mce_buttons, $plugin_array) {
foreach($mce_buttons as $args) {
$name = fansub_get_value_by_key($args, 'name');
$script = fansub_get_value_by_key($args, 'script');
if(!empty($name) && !empty($script)) {
$plugin_array = $this->add_mce_plugin_script($plugin_array, $name, $script);
}
}
return $plugin_array;
}
private function add_to_mce_list_button($buttons, $button, $type = 'button') {
if('button' == $type) {
$backup = array_pop($buttons);
$buttons[] = $button;
$buttons[] = $backup;
} else {
array_unshift($buttons, $button);
}
return $buttons;
}
private function loop_list_mce_buttons($mce_buttons, $buttons) {
foreach($mce_buttons as $args) {
$name = fansub_get_value_by_key($args, 'name');
$type = fansub_get_value_by_key($args, 'type', 'button');
if(!empty($name)) {
$buttons = $this->add_to_mce_list_button($buttons, $name, $type);
}
}
return $buttons;
}
public function mce_buttons($buttons) {
$buttons = $this->loop_list_mce_buttons($this->mce_buttons, $buttons);
return $buttons;
}
public function mce_buttons_2($buttons) {
$buttons = $this->loop_list_mce_buttons($this->mce_buttons_2, $buttons);
return $buttons;
}
public function mce_buttons_3($buttons) {
$buttons = $this->loop_list_mce_buttons($this->mce_buttons_3, $buttons);
return $buttons;
}
public function mce_buttons_4($buttons) {
$buttons = $this->loop_list_mce_buttons($this->mce_buttons_4, $buttons);
return $buttons;
}
}

784
fansub/classifieds.php Normal file
View File

@ -0,0 +1,784 @@
<?php
function fansub_taxonomy_province_base() {
$lang = fansub_get_language();
$default = 'province';
if('vi' == $lang) {
$default = 'tinh-thanh';
}
$option = get_option('fansub_permalink');
$base = fansub_get_value_by_key($option, 'province_base', $default);
$base = apply_filters('fansub_taxonomy_province_base', $base);
if(empty($base)) {
$base = $default;
}
return $base;
}
function fansub_taxonomy_district_base() {
$lang = fansub_get_language();
$default = 'district';
if('vi' == $lang) {
$default = 'quan-huyen';
}
$option = get_option('fansub_permalink');
$base = fansub_get_value_by_key($option, 'district_base', $default);
$base = apply_filters('fansub_taxonomy_district_base', $base);
if(empty($base)) {
$base = $default;
}
return $base;
}
function fansub_taxonomy_ward_base() {
$lang = fansub_get_language();
$default = 'ward';
if('vi' == $lang) {
$default = 'phuong-xa';
}
$option = get_option('fansub_permalink');
$base = fansub_get_value_by_key($option, 'ward_base', $default);
$base = apply_filters('fansub_taxonomy_ward_base', $base);
if(empty($base)) {
$base = $default;
}
return $base;
}
function fansub_taxonomy_hamlet_base() {
$lang = fansub_get_language();
$default = 'hamlet';
if('vi' == $lang) {
$default = 'thon-xom';
}
$option = get_option('fansub_permalink');
$base = fansub_get_value_by_key($option, 'hamlet_base', $default);
$base = apply_filters('fansub_taxonomy_hamlet_base', $base);
if(empty($base)) {
$base = $default;
}
return $base;
}
function fansub_taxonomy_street_base() {
$lang = fansub_get_language();
$default = 'street';
if('vi' == $lang) {
$default = 'duong-pho';
}
$option = get_option('fansub_permalink');
$base = fansub_get_value_by_key($option, 'street_base', $default);
$base = apply_filters('fansub_taxonomy_street_base', $base);
if(empty($base)) {
$base = $default;
}
return $base;
}
function fansub_taxonomy_price_base() {
$lang = fansub_get_language();
$default = 'price';
if('vi' == $lang) {
$default = 'muc-gia';
}
$option = get_option('fansub_permalink');
$base = fansub_get_value_by_key($option, 'price_base', $default);
$base = apply_filters('fansub_taxonomy_price_base', $base);
if(empty($base)) {
$base = $default;
}
return $base;
}
function fansub_taxonomy_acreage_base() {
$lang = fansub_get_language();
$default = 'acreage';
if('vi' == $lang) {
$default = 'dien-tich';
}
$option = get_option('fansub_permalink');
$base = fansub_get_value_by_key($option, 'acreage_base', $default);
$base = apply_filters('fansub_taxonomy_acreage_base', $base);
if(empty($base)) {
$base = $default;
}
return $base;
}
function fansub_taxonomy_classifieds_type_base() {
$lang = fansub_get_language();
$default = 'type';
if('vi' == $lang) {
$default = 'the-loai';
}
$option = get_option('fansub_permalink');
$base = fansub_get_value_by_key($option, 'classifieds_type_base', $default);
$base = apply_filters('fansub_taxonomy_classifieds_type_base', $base);
if(empty($base)) {
$base = $default;
}
return $base;
}
function fansub_taxonomy_classifieds_object_base() {
$lang = fansub_get_language();
$default = 'object';
if('vi' == $lang) {
$default = 'doi-tuong';
}
$option = get_option('fansub_permalink');
$base = fansub_get_value_by_key($option, 'classifieds_object_base', $default);
$base = apply_filters('fansub_taxonomy_classifieds_object_base', $base);
if(empty($base)) {
$base = $default;
}
return $base;
}
function fansub_taxonomy_salary_base() {
$lang = fansub_get_language();
$default = 'salary';
if('vi' == $lang) {
$default = 'muc-luong';
}
$option = get_option('fansub_permalink');
$base = fansub_get_value_by_key($option, 'salary_base', $default);
$base = apply_filters('fansub_taxonomy_salary_base', $base);
if(empty($base)) {
$base = $default;
}
return $base;
}
function fansub_administrative_boundaries_post_types() {
$types = array('post');
$types = apply_filters('fansub_administrative_boundaries_post_types', $types);
return $types;
}
function fansub_register_taxonomy_administrative_boundaries($post_type = null) {
if(!is_array($post_type)) {
$post_type = fansub_administrative_boundaries_post_types();
}
$lang = fansub_get_language();
$name = __('Provinces', 'fansub');
$singular = __('Province', 'fansub');
if('vi' == $lang) {
$name = 'Tỉnh / Thành phố';
$singular = $name;
}
$args = array(
'name' => $name,
'singular_name' => $singular,
'slug' => fansub_taxonomy_province_base(),
'taxonomy' => 'province',
'post_types' => $post_type
);
fansub_register_taxonomy($args);
$name = __('Districts', 'fansub');
$singular = __('District', 'fansub');
if('vi' == $lang) {
$name = 'Quận / Huyện';
$singular = $name;
}
$args = array(
'name' => $name,
'singular_name' => $singular,
'slug' => fansub_taxonomy_district_base(),
'taxonomy' => 'district',
'show_admin_column' => false,
'post_types' => $post_type
);
fansub_register_taxonomy($args);
$name = __('Wards', 'fansub');
$singular = __('Ward', 'fansub');
if('vi' == $lang) {
$name = 'Phường / Xã';
$singular = $name;
}
$args = array(
'name' => $name,
'singular_name' => $singular,
'slug' => fansub_taxonomy_ward_base(),
'taxonomy' => 'ward',
'show_admin_column' => false,
'post_types' => $post_type
);
fansub_register_taxonomy($args);
$hamlet = apply_filters('fansub_administrative_boundaries_hamlet', false);
if($hamlet) {
$name = __('Hamlets', 'fansub');
$singular = __('Hamlet', 'fansub');
if('vi' == $lang) {
$name = 'Thôn / Xóm';
$singular = $name;
}
$args = array(
'name' => $name,
'singular_name' => $singular,
'slug' => fansub_taxonomy_hamlet_base(),
'taxonomy' => 'hamlet',
'show_admin_column' => false,
'post_types' => $post_type
);
fansub_register_taxonomy($args);
}
$name = __('Streets', 'fansub');
$singular = __('Street', 'fansub');
if('vi' == $lang) {
$name = 'Đường / Phố';
$singular = $name;
}
$args = array(
'name' => $name,
'singular_name' => $singular,
'slug' => fansub_taxonomy_street_base(),
'taxonomy' => 'street',
'show_admin_column' => false,
'post_types' => $post_type
);
fansub_register_taxonomy($args);
}
function fansub_classifieds_get_saved_posts_page() {
$result = fansub_get_option_page('saved_posts_page', 'tin-da-luu', 'fansub-theme-setting', 'page-templates/saved-posts.php');
if(!is_a($result, 'WP_Post')) {
$result = fansub_get_page_by_template('page-templates/favorite-posts.php');
}
return apply_filters('fansub_classifieds_get_saved_posts_page', $result);
}
function fansub_classifieds_get_add_post_page() {
$result = fansub_get_option_page('add_post_page', 'dang-tin', 'fansub-theme-setting', 'page-templates/add-post.php');
return apply_filters('fansub_classifieds_get_add_post_page', $result);
}
function fansub_classifieds_get_manage_profile_page() {
$result = fansub_get_option_page('manage_profile_page', 'thong-tin-ca-nhan', 'fansub-theme-setting', 'page-templates/manage-profile.php');
return apply_filters('fansub_classifieds_get_manage_profile_page', $result);
}
function fansub_classifieds_get_price($post_id = null) {
$price = fansub_get_post_meta('price', $post_id);
if(empty($price)) {
$price = fansub_post_get_first_term($post_id, 'price');
if(is_a($price, 'WP_Term')) {
$price = $price->name;
} else {
$price = 'Thỏa thuận';
}
}
return $price;
}
function fansub_classifieds_get_administrative_boundary($post_id = null, $only_province = false) {
if(!fansub_id_number_valid($post_id)) {
$post_id = get_the_ID();
}
$terms = wp_get_post_terms($post_id, 'category');
$result = '';
if(fansub_array_has_value($terms)) {
$childs = array();
foreach($terms as $term) {
if($term->parent > 0) {
$childs[] = $term;
break;
}
}
if(fansub_array_has_value($childs)) {
$child = array_shift($childs);
$parent = get_category($child->parent);
while($parent->parent > 0) {
$child = $parent;
$parent = get_category($child->parent);
}
if($only_province) {
$result = $parent->name;
} else {
$result = $child->name . ', ' . $parent->name;
}
} else {
$term = array_shift($terms);
$result = $term->name;
}
}
return $result;
}
$use = apply_filters('fansub_classifieds_site', false);
if(!$use) {
return;
}
function fansub_classifieds_post_type_and_taxonomy() {
$lang = fansub_get_language();
$name = __('Types', 'fansub');
$singular = __('Type', 'fansub');
if('vi' == $lang) {
$name = 'Thể loại';
$singular = $name;
}
$args = array(
'name' => $name,
'singular_name' => $singular,
'slug' => fansub_taxonomy_classifieds_type_base(),
'taxonomy' => 'classifieds_type',
'post_types' => array('post')
);
fansub_register_taxonomy($args);
$custom_taxonomy = apply_filters('fansub_classifieds_custom_taxonomy', false);
if($custom_taxonomy) {
fansub_register_taxonomy_administrative_boundaries();
} else {
}
$name = __('Prices', 'fansub');
$singular = __('Price', 'fansub');
if('vi' == $lang) {
$name = 'Mức giá';
$singular = $name;
}
$args = array(
'name' => $name,
'singular_name' => $singular,
'slug' => fansub_taxonomy_price_base(),
'taxonomy' => 'price',
'show_admin_column' => false,
'post_types' => array('post')
);
fansub_register_taxonomy($args);
$name = __('Acreages', 'fansub');
$singular = __('Acreage', 'fansub');
if('vi' == $lang) {
$name = 'Diện tích';
$singular = $name;
}
$args = array(
'name' => $name,
'singular_name' => $singular,
'slug' => fansub_taxonomy_acreage_base(),
'taxonomy' => 'acreage',
'show_admin_column' => false,
'post_types' => array('post')
);
fansub_register_taxonomy($args);
$use = apply_filters('fansub_use_taxonomy_classifieds_object', false);
if($use) {
$name = __('Objects', 'fansub');
$singular = __('Object', 'fansub');
if('vi' == $lang) {
$name = 'Đối tượng';
$singular = $name;
}
$args = array(
'name' => $name,
'singular_name' => $singular,
'slug' => fansub_taxonomy_classifieds_object_base(),
'taxonomy' => 'classifieds_object',
'show_admin_column' => false,
'post_types' => array('post')
);
fansub_register_taxonomy($args);
}
$use = apply_filters('fansub_use_taxonomy_salary', false);
if($use) {
$name = __('Salaries', 'fansub');
$singular = __('Salary', 'fansub');
if('vi' == $lang) {
$name = 'Mức lương';
$singular = $name;
}
$args = array(
'name' => $name,
'singular_name' => $singular,
'slug' => fansub_taxonomy_salary_base(),
'taxonomy' => 'salary',
'show_admin_column' => false,
'post_types' => array('post')
);
fansub_register_taxonomy($args);
}
fansub_register_post_type_news();
}
add_action('init', 'fansub_classifieds_post_type_and_taxonomy', 10);
if('post.php' == $GLOBALS['pagenow'] || 'post-new.php' == $GLOBALS['pagenow']) {
$current_user = wp_get_current_user();
$meta = new HOCWP_Meta('post');
$meta->add_post_type('post');
$meta->set_title(__('General Information', 'fansub'));
$meta->set_id('classifieds_general_information');
$meta->add_field(array('id' => 'address', 'label' => __('Address:', 'fansub'), 'class' => 'fansub-geo-address', 'default' => get_user_meta($current_user->ID, 'address', true)));
$meta->add_field(array('id' => 'price', 'label' => __('Price:', 'fansub')));
$meta->add_field(array('id' => 'phone', 'label' => __('Phone:', 'fansub'), 'default' => get_user_meta($current_user->ID, 'phone', true)));
$meta->add_field(array('id' => 'email', 'label' => __('Email:', 'fansub'), 'default' => $current_user->user_email));
$meta->add_field(array('id' => 'acreage', 'label' => __('Acreage:', 'fansub')));
$meta->init();
fansub_meta_box_editor_gallery(array('post_type' => 'post'));
fansub_meta_box_google_maps();
}
function fansub_classifieds_filter_taxonomy_base($base, $taxonomy) {
switch($taxonomy) {
case 'classifieds_type':
$base = fansub_taxonomy_classifieds_type_base();
break;
}
return $base;
}
add_filter('fansub_remove_term_base_taxonomy_base', 'fansub_classifieds_filter_taxonomy_base', 99, 2);
function fansub_classifieds_scripts() {
if(is_single()) {
fansub_register_lib_google_maps();
} elseif(is_page()) {
$post_id = get_the_ID();
$add_post_page = fansub_classifieds_get_add_post_page();
if(is_a($add_post_page, 'WP_Post')) {
if($post_id == $add_post_page->ID) {
fansub_register_lib_google_maps();
}
}
}
}
add_action('wp_enqueue_scripts', 'fansub_classifieds_scripts');
function fansub_classifieds_admin_scripts() {
global $pagenow;
if('post-new.php' == $pagenow || 'post.php' == $pagenow) {
fansub_register_lib_google_maps();
}
}
add_action('admin_enqueue_scripts', 'fansub_classifieds_admin_scripts');
function fansub_classifieds_admin_body_class($classes) {
global $pagenow;
fansub_add_string_with_space_before($classes, 'classifieds');
if('post-new.php' == $pagenow || 'post.php' == $pagenow) {
fansub_add_string_with_space_before($classes, 'fansub-google-maps');
}
return $classes;
}
add_filter('admin_body_class', 'fansub_classifieds_admin_body_class');
function fansub_classifieds_admin_class($classes) {
$classes[] = 'classifieds';
if(is_single()) {
$classes[] = 'fansub-google-maps';
} elseif(is_page()) {
$post_id = get_the_ID();
$add_post_page = fansub_classifieds_get_add_post_page();
if(is_a($add_post_page, 'WP_Post')) {
if($post_id == $add_post_page->ID) {
$classes[] = 'fansub-google-maps';
}
}
}
return $classes;
}
add_filter('body_class', 'fansub_classifieds_admin_class');
function fansub_classifieds_pre_post_thumbnail($url, $post_id) {
if(empty($url)) {
$gallery = fansub_get_post_meta('gallery', $post_id);
$url = fansub_get_first_image_source($gallery);
}
return $url;
}
add_filter('fansub_post_pre_post_thumbnail', 'fansub_classifieds_pre_post_thumbnail', 10, 2);
function fansub_classifieds_widget_post_after_post($args, $instance, $widget) {
global $post;
if(is_a($post, 'WP_Post')) {
if('post' == $post->post_type) {
$modified = get_post_modified_time('U', false, $post);
$salary = fansub_post_get_first_term($post->ID, 'salary');
?>
<div class="metas">
<div class="pull-left">
<?php
if(is_a($salary, 'WP_Term')) {
?>
<div class="meta price">
<span><strong><?php echo $salary->name; ?></strong></span>
</div>
<?php
} else {
?>
<div class="meta price">
<span><strong><?php echo fansub_classifieds_get_price(); ?></strong></span>
</div>
<?php
}
?>
</div>
<div class="pull-right">
<div class="meta modified">
<?php echo fansub_human_time_diff_to_now($modified) . ' trước'; ?>
</div>
</div>
</div>
<?php
}
}
}
add_action('fansub_widget_post_after_post', 'fansub_classifieds_widget_post_after_post', 10, 3);
function fansub_classifieds_pre_get_posts(WP_Query $query) {
if($query->is_main_query()) {
if(is_search()) {
$type = fansub_get_value_by_key($_REQUEST, 'type');
$province = fansub_get_value_by_key($_REQUEST, 'province');
$district = fansub_get_value_by_key($_REQUEST, 'district');
$ward = fansub_get_value_by_key($_REQUEST, 'ward');
$street = fansub_get_value_by_key($_REQUEST, 'street');
$price = fansub_get_value_by_key($_REQUEST, 'price');
$acreage = fansub_get_value_by_key($_REQUEST, 'acreage');
$object = fansub_get_value_by_key($_REQUEST, 'object');
$salary = fansub_get_value_by_key($_REQUEST, 'salary');
$tax_query = array(
'relation' => 'AND'
);
if(fansub_id_number_valid($type)) {
$tax_item = array(
'taxonomy' => 'classifieds_type',
'field' => 'id',
'terms' => $type
);
fansub_query_sanitize_tax_query($tax_item, $tax_query);
}
if(fansub_id_number_valid($province)) {
$tax_item = array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => $province
);
fansub_query_sanitize_tax_query($tax_item, $tax_query);
}
if(fansub_id_number_valid($district)) {
$tax_item = array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => $district
);
fansub_query_sanitize_tax_query($tax_item, $tax_query);
}
if(fansub_id_number_valid($ward)) {
$tax_item = array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => $ward
);
fansub_query_sanitize_tax_query($tax_item, $tax_query);
}
if(fansub_id_number_valid($street)) {
$tax_item = array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => $street
);
fansub_query_sanitize_tax_query($tax_item, $tax_query);
}
unset($query->query['price']);
unset($query->query_vars['price']);
if(fansub_id_number_valid($price)) {
$tax_item = array(
'taxonomy' => 'price',
'field' => 'id',
'terms' => $price
);
fansub_query_sanitize_tax_query($tax_item, $tax_query);
}
unset($query->query['acreage']);
unset($query->query_vars['acreage']);
if(fansub_id_number_valid($acreage)) {
$tax_item = array(
'taxonomy' => 'acreage',
'field' => 'id',
'terms' => $acreage
);
fansub_query_sanitize_tax_query($tax_item, $tax_query);
}
if(fansub_id_number_valid($object)) {
$tax_item = array(
'taxonomy' => 'classifieds_object',
'field' => 'id',
'terms' => $object
);
fansub_query_sanitize_tax_query($tax_item, $tax_query);
}
unset($query->query['salary']);
unset($query->query_vars['salary']);
if(fansub_id_number_valid($salary)) {
$tax_item = array(
'taxonomy' => 'salary',
'field' => 'id',
'terms' => $salary
);
fansub_query_sanitize_tax_query($tax_item, $tax_query);
}
$tax_query = fansub_get_value_by_key($tax_query, 'tax_query', $tax_query);
$tax_query['relation'] = 'AND';
$query->set('tax_query', $tax_query);
$query->set('post_type', 'post');
}
}
return $query;
}
if(!is_admin()) add_action('pre_get_posts', 'fansub_classifieds_pre_get_posts');
function fansub_classifieds_admin_pre_get_posts($query) {
global $pagenow, $post_type;
$user = wp_get_current_user();
if('edit.php' == $pagenow && !fansub_is_admin()) {
$query->set('author', $user->ID);
}
return $query;
}
if(is_admin() && fansub_prevent_author_see_another_post()) add_action('pre_get_posts', 'fansub_classifieds_admin_pre_get_posts');
function fansub_classifieds_save_post($post_id) {
if(!fansub_can_save_post($post_id)) {
return;
}
global $post_type;
if(empty($post_type)) {
$post_type = fansub_get_current_post_type();
}
if(empty($post_type) || 'post' == $post_type) {
if(fansub_is_subscriber()) {
if(get_post_status($post_id) == 'publish') {
$post_data = array(
'ID' => $post_id,
'post_status' => 'pending'
);
wp_update_post($post_data);
}
}
if(is_admin() && !HOCWP_DOING_AJAX) {
$taxonomies = fansub_post_get_taxonomies(get_post($post_id), 'objects');
$custom_taxonomies = array();
$salary = fansub_get_value_by_key($taxonomies, 'salary');
$acreage = fansub_get_value_by_key($taxonomies, 'acreage');
$price = fansub_get_value_by_key($taxonomies, 'price');
$classifieds_object = fansub_get_value_by_key($taxonomies, 'classifieds_object');
if(fansub_object_valid($salary)) {
//$custom_taxonomies[$salary->name] = $salary;
}
if(fansub_object_valid($price)) {
//$custom_taxonomies[$price->name] = $price;
}
if(fansub_object_valid($acreage)) {
//$custom_taxonomies[$acreage->name] = $acreage;
}
if(fansub_object_valid($classifieds_object)) {
//$custom_taxonomies[$classifieds_object->name] = $classifieds_object;
}
unset($taxonomies['salary']);
unset($taxonomies['acreage']);
unset($taxonomies['price']);
unset($taxonomies['classifieds_object']);
$errors = array();
if(fansub_array_has_value($taxonomies)) {
foreach($taxonomies as $taxonomy) {
if($taxonomy->hierarchical) {
$terms = wp_get_post_terms($post_id, $taxonomy->name);
if(!fansub_array_has_value($terms)) {
//$errors[] = sprintf(__('Please set %s for this post.', 'fansub'), '<strong>' . $taxonomy->labels->singular_name . '</strong>');
}
}
}
}
$acreages = (fansub_object_valid($acreage)) ? wp_get_post_terms($post_id, $acreage->name) : '';
$prices = (fansub_object_valid($price)) ? wp_get_post_terms($post_id, $price->name) : '';
$salaries = (fansub_object_valid($salary)) ? wp_get_post_terms($post_id, $salary->name) : '';
$objects = (fansub_object_valid($classifieds_object)) ? wp_get_post_terms($post_id, $classifieds_object->name) : '';
$terms = array();
foreach($custom_taxonomies as $taxonomy) {
if($taxonomy->hierarchical) {
$post_terms = wp_get_post_terms($post_id, $taxonomy->name);
if(fansub_array_has_value($post_terms)) {
$terms = array_merge($terms, $post_terms);
}
}
}
if(!fansub_array_has_value($errors) && !fansub_array_has_value($terms)) {
//$errors[] = __('Please set term for this post in right way.', 'fansub');
}
if(fansub_array_has_value($errors)) {
if(get_post_status($post_id) == 'publish') {
$post_data = array(
'ID' => $post_id,
'post_status' => 'pending'
);
wp_update_post($post_data);
}
set_transient('fansub_save_classifieds_post_' . $post_id . '_error', $errors);
}
}
}
}
add_action('save_post', 'fansub_classifieds_save_post', 99);
function fansub_classifieds_admin_notice() {
$post_id = fansub_get_method_value('post', 'request');
if(fansub_id_number_valid($post_id)) {
$transient_name = 'fansub_save_classifieds_post_' . $post_id . '_error';
$errors = get_transient($transient_name);
if(false !== $errors) {
foreach($errors as $error) {
fansub_admin_notice(array('text' => $error, 'error' => true));
}
delete_transient($transient_name);
}
}
}
add_action('admin_notices', 'fansub_classifieds_admin_notice');
function fansub_classifieds_admin_menu() {
$role = fansub_get_user_role(wp_get_current_user());
if('subscriber' == $role) {
$post_types = get_post_types();
unset($post_types['post']);
foreach($post_types as $post_type) {
remove_menu_page('edit.php?post_type=' . $post_type);
}
remove_menu_page('edit-comments.php');
remove_menu_page('tools.php');
}
}
add_action('admin_menu', 'fansub_classifieds_admin_menu', 99);
function fansub_classifieds_admin_init() {
global $pagenow;
$role = get_role('subscriber');
if(fansub_object_valid($role)) {
$role->add_cap('publish_posts');
$role->add_cap('edit_posts');
}
if('post-new.php' == $pagenow) {
if(fansub_is_subscriber()) {
$post_type = fansub_get_current_post_type();
if(!empty($post_type) && 'post' !== $post_type) {
wp_redirect(admin_url());
exit;
}
}
}
}
add_action('admin_init', 'fansub_classifieds_admin_init', 0);
add_filter('fansub_use_addthis', '__return_true');
function fansub_classifieds_on_wp_run() {
if(!is_user_logged_in()) {
if(is_page_template('page-templates/favorite-posts.php') || is_page_template('page-templates/add-post.php') || is_page_template('page-templates/account.php')) {
wp_redirect(wp_login_url());
exit;
}
}
}
add_action('wp', 'fansub_classifieds_on_wp_run');

187
fansub/comment.php Normal file
View File

@ -0,0 +1,187 @@
<?php
if(!function_exists('add_filter')) exit;
function fansub_comment_wp_insert_comment($comment_id, $comment_object) {
}
add_action('wp_insert_comment', 'fansub_comment_wp_insert_comment', 10, 2);
function fansub_comment_transition_comment_status($new_status, $old_status, $comment) {
if($old_status != $new_status) {
if('approved' === $new_status) {
do_action('fansub_comment_approved', $comment);
$notify_me = get_comment_meta($comment->comment_ID, 'notify_me', true);
if(!empty($notify_me)) {
}
}
fansub_delete_transient('fansub_top_commenters');
do_action('fansub_comment_status_changed', $comment);
}
}
add_action('transition_comment_status', 'fansub_comment_transition_comment_status', 10, 3);
function fansub_comment_form_default_fields($fields) {
$commenter = wp_get_current_commenter();
$user = wp_get_current_user();
$user_identity = $user->exists() ? $user->display_name : '';
$format = current_theme_supports('html5', 'comment-form') ? 'html5' : 'xhtml';
$format = apply_filters('fansub_comment_form_format', $format);
$req = get_option('require_name_email');
$aria_req = ($req ? "aria-required='true'" : '');
$html_req = ($req ? "required='required'" : '');
$required_html = '';
fansub_add_string_with_space_before($required_html, $aria_req);
fansub_add_string_with_space_before($required_html, $html_req);
$html5 = 'html5' === $format;
$fields = array(
'author' => '<p class="comment-form-author">' . '<label for="author">' . __('Name', 'fansub') . ($req ? ' <span class="required">*</span>' : '') . '</label> ' .
'<input id="author" name="author" type="text" value="' . esc_attr($commenter['comment_author']) . '" size="30" ' . $required_html . ' /></p>',
'email' => '<p class="comment-form-email"><label for="email">' . __('Email', 'fansub') . ($req ? ' <span class="required">*</span>' : '') . '</label> ' .
'<input id="email" name="email" ' . ($html5 ? 'type="email"' : 'type="text"') . ' value="' . esc_attr($commenter['comment_author_email']) . '" size="30" aria-describedby="email-notes" ' . $required_html . ' /></p>',
'url' => '<p class="comment-form-url"><label for="url">' . __('Website', 'fansub') . '</label> ' .
'<input id="url" name="url" ' . ($html5 ? 'type="url"' : 'type="text"') . ' value="' . esc_attr($commenter['comment_author_url']) . '" size="30" /></p>',
);
return $fields;
}
add_filter('comment_form_default_fields', 'fansub_comment_form_default_fields');
function fansub_comment_form_defaults($defaults) {
$commenter = wp_get_current_commenter();
$user = wp_get_current_user();
$user_identity = $user->exists() ? $user->display_name : '';
$format = current_theme_supports('html5', 'comment-form') ? 'html5' : 'xhtml';
$format = apply_filters('fansub_comment_form_format', $format);
$req = get_option('require_name_email');
$aria_req = ($req ? " aria-required='true'" : '');
$html_req = ($req ? " required='required'" : '');
$required_text = sprintf(' ' . __('Required fields are marked %s', 'fansub'), '<span class="required">*</span>');
$html5 = 'html5' === $format;
$defaults = array(
'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x('Comment', 'noun') . '</label> <textarea id="comment" name="comment" cols="45" rows="8" aria-required="true" required="required"></textarea></p>',
'must_log_in' => '<p class="must-log-in">' . sprintf(__('You must be <a href="%s">logged in</a> to post a comment.', 'fansub'), wp_login_url(apply_filters('the_permalink', get_permalink(get_the_ID())))) . '</p>',
'logged_in_as' => '<p class="logged-in-as">' . sprintf(__('Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>', 'fansub'), get_edit_user_link(), $user_identity, wp_logout_url(apply_filters('the_permalink', get_permalink(get_the_ID())))) . '</p>',
'comment_notes_before' => '<p class="comment-notes"><span id="email-notes">' . __('Your email address will not be published.', 'fansub') . '</span>'. ($req ? $required_text : '') . '</p>',
'comment_notes_after' => '',
'id_form' => 'commentform',
'id_submit' => 'submit',
'class_submit' => 'submit',
'name_submit' => 'submit',
'title_reply' => '<span class="title-text">' . __('Leave a Reply', 'fansub') . '</span>',
'title_reply_to' => __('Leave a Reply to %s', 'fansub'),
'cancel_reply_link' => __('Click here to cancel reply.', 'fansub'),
'label_submit' => __('Post Comment', 'fansub'),
'submit_button' => '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />',
'submit_field' => '<p class="form-submit">%1$s %2$s</p>',
'format' => 'html5'
);
return $defaults;
}
add_filter('comment_form_defaults', 'fansub_comment_form_defaults');
function fansub_wp_list_comments_args($args) {
$args['reply_text'] = '<i class="fa fa-reply"></i><span class="text">' . __('Reply', 'fansub') . '</span>';
return $args;
}
add_filter('wp_list_comments_args', 'fansub_wp_list_comments_args', 10);
function fansub_get_comment_likes($comment_id) {
$result = get_comment_meta($comment_id, 'likes', true);
$result = absint($result);
return $result;
}
function fansub_facebook_comment($args = array()) {
$args = apply_filters('fansub_facebook_comment_args', $args);
$colorscheme = isset($args['colorscheme']) ? $args['colorscheme'] : 'light';
$colorscheme = apply_filters('fansub_facebook_comment_colorscheme', $colorscheme, $args);
$href = isset($args['href']) ? $args['href'] : '';
if(empty($href)) {
if(is_single() || is_page() || is_singular()) {
$href = get_the_permalink();
}
}
if(empty($href)) {
$href = $this->get_current_url();
}
$href = apply_filters('fansub_facebook_comment_href', $href, $args);
$mobile = isset($args['mobile']) ? $args['mobile'] : '';
$num_posts = isset($args['num_posts']) ? $args['num_posts'] : 10;
$num_posts = apply_filters('fansub_facebook_comment_num_posts', $num_posts, $args);
$order_by = isset($args['order_by']) ? $args['order_by'] : 'social';
$width = isset($args['width']) ? $args['width'] : '100%';
$width = apply_filters('fansub_facebook_comment_width', $width, $args);
$loading_text = fansub_get_value_by_key($args, 'loading_text', __('Loading...', 'fansub'));
$div = new FANSUB_HTML('div');
$div->set_class('fb-comments');
$atts = array(
'data-colorscheme' => $colorscheme,
'data-href' => $href,
'data-mobile' => $mobile,
'data-numposts' => $num_posts,
'data-order-by' => $order_by,
'data-width' => $width
);
$atts = apply_filters('fansub_facebook_comment_attributes', $atts, $args);
$div->set_attribute_array($atts);
$div->set_text($loading_text);
$div->output();
}
function fansub_google_comment() {
?>
<script src="https://apis.google.com/js/plusone.js"></script>
<div id="google_comments"><?php _e('Loading...', 'fansub'); ?></div>
<script>
gapi.comments.render('google_comments', {
href: window.location,
width: '624',
first_party_property: 'BLOGGER',
view_type: 'FILTERED_POSTMOD'
});
</script>
<?php
}
function fansub_get_top_commenters($number = 5, $time = 'all', $condition = '') {
$transient_name = 'fansub_top_commenters_' . $time . '_' . $number;
$transient_name = fansub_sanitize_id($transient_name);
if(false === ($results = get_transient($transient_name))) {
global $wpdb;
$sql = 'SELECT COUNT(comment_author_email) AS comments_count, comment_author_email, comment_author, comment_author_url, user_id FROM ' . $wpdb->comments . '
WHERE comment_author_email != "" AND comment_type = "" AND comment_approved = 1';
$expires = HOUR_IN_SECONDS;
switch($time) {
case 'today':
$sql .= ' AND DAY(comment_date) = DAY(CURDATE()) AND MONTH(comment_date) = MONTH(CURDATE()) AND YEAR(comment_date) = YEAR(CURDATE())';
break;
case 'week':
case 'this_week':
$sql .= ' AND YEARWEEK(comment_date) = YEARWEEK(NOW())';
$expires = 12 * HOUR_IN_SECONDS;
break;
case 'month':
case 'this_month':
$sql .= ' AND MONTH(comment_date) = MONTH(CURDATE()) AND YEAR(comment_date) = YEAR(CURDATE())';
$expires = DAY_IN_SECONDS;
break;
case 'year':
case 'this_year':
$sql .= ' AND YEAR(comment_date) = YEAR(CURDATE())';
$expires = 2 * DAY_IN_SECONDS;
break;
}
$condition = trim($condition);
if(!empty($condition)) {
$sql .= ' ' . $condition;
}
$sql .= ' GROUP BY comment_author_email ORDER BY comments_count DESC, comment_author ASC LIMIT ' . $number;
$results = $wpdb->get_results($sql);
set_transient($transient_name, $results, $expires);
}
return $results;
}
function fansub_comment_inserted_hook($id, $comment) {
fansub_delete_transient('fansub_top_commenters');
}
add_action('wp_insert_comment', 'fansub_comment_inserted_hook', 10, 2);

748
fansub/coupon.php Normal file
View File

@ -0,0 +1,748 @@
<?php
function fansub_coupon_store_base() {
$option = get_option('fansub_permalink');
$base = fansub_get_value_by_key($option, 'coupon_store_base', 'store');
$base = apply_filters('fansub_coupon_store_base', $base);
if(empty($base)) {
$base = 'store';
}
return $base;
}
function fansub_coupon_category_base() {
$option = get_option('fansub_permalink');
$base = fansub_get_value_by_key($option, 'coupon_category_base', 'coupon-cat');
$base = apply_filters('fansub_coupon_category_base', $base);
if(empty($base)) {
$base = 'coupon-cat';
}
return $base;
}
function fansub_coupon_tag_base() {
$option = get_option('fansub_permalink');
$base = fansub_get_value_by_key($option, 'coupon_tag_base', 'coupon-tag');
$base = apply_filters('fansub_coupon_tag_base', $base);
if(empty($base)) {
$base = 'coupon-tag';
}
return $base;
}
function fansub_coupon_type_base() {
$option = get_option('fansub_permalink');
$base = fansub_get_value_by_key($option, 'coupon_type_base', 'coupon-type');
$base = apply_filters('fansub_coupon_type_base', $base);
if(empty($base)) {
$base = 'coupon-type';
}
return $base;
}
function fansub_coupon_install_post_type_and_taxonomy() {
$args = array(
'name' => __('Coupons', 'fansub'),
'singular_name' => __('Coupon', 'fansub'),
'supports' => array('editor', 'comments', 'thumbnail'),
'slug' => 'coupon',
'taxonomies' => array('store', 'coupon_cat', 'coupon_tag', 'coupon_type'),
'show_in_admin_bar' => true
);
fansub_register_post_type($args);
$args = array(
'name' => __('Events', 'fansub'),
'singular_name' => __('Event', 'fansub'),
'supports' => array('editor', 'comments', 'thumbnail'),
'slug' => 'event',
'show_in_admin_bar' => true
);
fansub_register_post_type($args);
$args = array(
'name' => __('Stores', 'fansub'),
'singular_name' => __('Store', 'fansub'),
'taxonomy' => 'store',
'slug' => fansub_coupon_store_base(),
'post_types' => array('coupon')
);
fansub_register_taxonomy($args);
$args = array(
'name' => __('Coupon Categories', 'fansub'),
'singular_name' => __('Coupon Category', 'fansub'),
'menu_name' => __('Categories', 'fansub'),
'slug' => fansub_coupon_category_base(),
'taxonomy' => 'coupon_cat',
'post_types' => array('coupon')
);
fansub_register_taxonomy($args);
$args = array(
'name' => __('Coupon Tags', 'fansub'),
'singular_name' => __('Coupon Tag', 'fansub'),
'menu_name' => __('Tags', 'fansub'),
'slug' => fansub_coupon_tag_base(),
'taxonomy' => 'coupon_tag',
'hierarchical' => false,
'post_types' => array('coupon')
);
fansub_register_taxonomy($args);
$args = array(
'name' => __('Coupon Types', 'fansub'),
'singular_name' => __('Coupon Type', 'fansub'),
'menu_name' => __('Types', 'fansub'),
'slug' => fansub_coupon_type_base(),
'taxonomy' => 'coupon_type',
'post_types' => array('coupon')
);
fansub_register_taxonomy($args);
}
function fansub_get_coupon_url($post_id = null) {
if(!fansub_id_number_valid($post_id)) {
$out = get_query_var('out');
if(!empty($out)) {
if(fansub_id_number_valid($out)) {
$post_id = $out;
} else {
$post = fansub_get_post_by_slug($out);
if(is_a($post, 'WP_Post')) {
$post_id = $post->ID;
}
}
} else {
$post = fansub_get_post_by_slug($post_id);
if(is_a($post, 'WP_Post')) {
$post_id = $post->ID;
} else {
$post_id = get_the_ID();
}
}
}
$url = fansub_get_coupon_meta('url', $post_id);
if(empty($url)) {
$store = fansub_get_coupon_store($post_id);
if(is_a($store, 'WP_Term')) {
$url = fansub_get_store_url($store->term_id);
}
}
return $url;
}
function fansub_get_store_url($id) {
return get_term_meta($id, 'site', true);
}
function fansub_get_top_store_by_coupon_count($args = array()) {
return fansub_term_get_by_count('store', $args);
}
function fansub_get_top_category_by_coupon_count($args = array()) {
return fansub_term_get_by_count('coupon_cat', $args);
}
function fansub_get_coupon_categories($args = array()) {
return fansub_get_terms('coupon_cat', $args);
}
function fansub_get_coupon_stores($args = array()) {
return fansub_get_terms('store', $args);
}
function fansub_get_coupon_hint($post_id = null) {
$code = fansub_get_coupon_code($post_id);
$len = strlen($code);
if($len > 3) {
$len = intval($len/2);
}
if($len < 3) {
$len = 3;
}
if($len > 10) {
$len = 10;
}
$len = -$len;
$code = substr($code, $len);
return $code;
}
function fansub_get_coupon_code($post_id = null) {
if(!fansub_id_number_valid($post_id)) {
$post_id = get_the_ID();
}
$code = fansub_get_coupon_meta('coupon_code', $post_id);
if(empty($code)) {
$code = fansub_get_coupon_meta('code', $post_id);
}
if(empty($code)) {
$code = fansub_get_coupon_meta('wpcf-coupon-code', $post_id);
}
return $code;
}
function fansub_get_coupon_meta($meta_key, $post_id = null) {
return fansub_get_post_meta($meta_key, $post_id);
}
function fansub_get_coupon_percent_label($post_id = null) {
return fansub_get_coupon_meta('percent_label', $post_id);
}
function fansub_get_coupon_text_label($post_id = null) {
return fansub_get_coupon_meta('text_label', $post_id);
}
function fansub_get_coupon_expired_date($post_id = null) {
return fansub_get_coupon_meta('expired_date', $post_id);
}
function fansub_get_coupon_type_term($post_id = null) {
if(!fansub_id_number_valid($post_id)) {
$post_id = get_the_ID();
}
$result = array(
'code'
);
$terms = wp_get_post_terms($post_id, 'coupon_type');
$term = current($terms);
return $term;
}
function fansub_get_coupon_type_object($type = 'code') {
$term = new WP_Error();
switch($type) {
case 'deal':
$term = fansub_get_term_by_slug('deal', 'coupon_type');
if(!is_a($term, 'WP_Term')) {
$term = fansub_get_term_by_slug('sales', 'coupon_type');
}
if(!is_a($term, 'WP_Term')) {
$term = fansub_get_term_by_slug('promotion', 'coupon_type');
}
break;
default:
$term = fansub_get_term_by_slug('promo-codes', 'coupon_type');
if(!is_a($term, 'WP_Term')) {
$term = fansub_get_term_by_slug('promo-code', 'coupon_type');
}
if(!is_a($term, 'WP_Term')) {
$term = fansub_get_term_by_slug('code', 'coupon_type');
}
if(!is_a($term, 'WP_Term')) {
$term = fansub_get_term_by_slug('coupon-code', 'coupon_type');
}
if(!is_a($term, 'WP_Term')) {
$term = fansub_get_term_by_slug('coupon-code', 'coupon_type');
}
}
return $term;
}
function fansub_coupon_get_store_by_category($category) {
$args = array(
'post_type' => 'coupon',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => $category->taxonomy,
'field' => 'id',
'terms' => array($category->term_id)
)
)
);
$query = fansub_query($args);
$result = array();
if($query->have_posts()) {
while($query->have_posts()) {
$query->the_post();
$terms = wp_get_object_terms(get_the_ID(), 'store');
if(fansub_array_has_value($terms)) {
$result = array_merge($result, $terms);
}
}
wp_reset_postdata();
}
$result = array_unique($result, SORT_REGULAR);
return $result;
}
function fansub_get_event_coupons($event_id, $args = array()) {
$args['meta_key'] = 'event';
$args['meta_value_num'] = $event_id;
$args['post_type'] = 'coupon';
return fansub_query($args);
}
function fansub_get_expired_coupons($args = array()) {
$timestamp = current_time('timestamp', 0);
$args['meta_key'] = 'expired_date';
$args['meta_value'] = $timestamp;
$args['meta_compare'] = '<';
$args['meta_type'] = 'numeric';
$meta_item = array(
'key' => 'expired_date',
'value' => $timestamp,
'compare' => '<'
);
if(isset($args['meta_query'])) {
foreach($args['meta_query'] as $i => $meta) {
if(fansub_array_has_value($meta)) {
foreach($meta as $j => $child_meta) {
if('key' == $j && 'expired_date' == $child_meta) {
unset($args['meta_query'][$i]);
}
}
}
}
}
$args = fansub_query_sanitize_meta_query($meta_item, $args);
$meta_item = array(
'key' => 'expired_date',
'compare' => 'EXISTS'
);
$args = fansub_query_sanitize_meta_query($meta_item, $args);
$args['meta_query']['relation'] = 'AND';
$args['expired_coupon'] = true;
return fansub_query($args);
}
function fansub_get_coupon_type($post_id = null) {
$term = fansub_get_coupon_type_term($post_id);
$result = array();
if(is_a($term, 'WP_Term')) {
$type = 'code';
$text = $term->name;
switch($term->slug) {
case 'deal':
case 'online-deal':
case 'sale':
case 'sales':
$type = 'deal';
$text = 'Deal';
break;
case 'in-store-coupons':
case 'in-store-coupon':
case 'in-store':
case 'print':
case 'printable':
$type = 'printable';
$text = 'Printable';
break;
default:
$type = 'code';
$text = 'Coupon';
}
$result[$type] = $text;
}
return $result;
}
function fansub_coupon_label_html($percent, $text, $type) {
?>
<div class="coupon-label-context text-center">
<p class="percent"><?php echo $percent; ?></p>
<p class="text"><?php echo $text; ?></p>
</div>
<div class="coupon-type text-center">
<span><?php echo $type; ?></span>
</div>
<?php
}
function fansub_coupon_filter_bar_html($args = array()) {
$term = fansub_get_value_by_key($args, 'term');
$posts_per_page = fansub_get_value_by_key($args, 'posts_per_page', fansub_get_posts_per_page());
$code_count = absint(fansub_get_value_by_key($args, 'code_count'));
$deal_count = absint(fansub_get_value_by_key($args, 'deal_count'));
?>
<ul data-store="<?php echo $term->term_id; ?>" data-paged="<?php echo fansub_get_paged(); ?>" data-posts-per-page="<?php echo $posts_per_page; ?>" class="filter">
<li>
<a href="#" data-filter="all" class="active">All (<?php echo $term->count; ?>)</a>
</li>
<li>
<a href="#" data-filter="coupon-code">Coupon Codes (<?php echo $code_count; ?>)</a>
</li>
<li>
<a href="#" data-filter="promotion">Deals (<?php echo $deal_count; ?>)</a>
</li>
</ul>
<?php
}
function fansub_coupon_button_html($args = array()) {
$post_id = fansub_get_value_by_key($args, 'post_id', get_the_ID());
$type = fansub_get_value_by_key($args, 'type');
$code_hint = fansub_get_value_by_key($args, 'code_hint');
$type_text = fansub_get_value_by_key($args, 'type_text');
$out_url = fansub_get_value_by_key($args, 'out_url', fansub_get_coupon_out_url($post_id));
?>
<a href="#coupon_box_<?php echo $post_id; ?>" data-post-id="<?php echo $post_id; ?>" class="code type-<?php echo $type; ?>" data-out-url="<?php echo $out_url; ?>" data-toggle="modal">
<span class="cc"><?php echo $code_hint; ?></span>
<span class="cc-label"><?php printf(__('Get %s', 'fansub'), $type_text); ?></span>
</a>
<?php
}
function fansub_coupon_button_code_html($args = array()) {
$post_id = fansub_get_value_by_key($args, 'post_id', get_the_ID());
$code = fansub_get_value_by_key($args, 'code');
if(empty($code) && fansub_id_number_valid($post_id)) {
$code = fansub_get_coupon_code($post_id);
}
if(empty($code)) {
return;
}
$out_url = fansub_get_value_by_key($args, 'out_url', fansub_get_coupon_out_url($post_id));
$button_class = fansub_get_value_by_key($args, 'button_class');
fansub_add_string_with_space_before($button_class, 'copy-button');
$input_class = fansub_get_value_by_key($args, 'input_class');
fansub_add_string_with_space_before($input_class, 'text');
?>
<div class="code clearfix">
<input class="<?php echo $input_class; ?>" type="text" value="<?php echo $code; ?>" readonly>
<a class="<?php echo $button_class; ?>" data-clipboard-text="<?php echo $code; ?>" data-out-url="<?php echo $out_url; ?>">Copy</a>
</div>
<?php
}
function fansub_coupon_vote_comment_html($args = array()) {
$result = fansub_get_value_by_key($args, 'result');
$post_id = fansub_get_value_by_key($args, 'post_id', get_the_ID());
if(empty($result)) {
$likes = fansub_get_post_meta('likes', $post_id);
$dislikes = fansub_get_post_meta('dislikes', $post_id);
$result = fansub_percentage($likes, $dislikes);
$result = apply_filters('fansub_coupon_rating_percentage', $result, $likes, $dislikes);
$result .= '%';
}
?>
<p class="vote-result" data-post-id="<?php the_ID(); ?>">
<i class="fa fa-thumbs-o-up"></i>
<span><?php printf(__('%s Success', 'fansub'), $result); ?></span>
</p>
<?php
if(comments_open($post_id) || get_comments_number($post_id)) {
?>
<p class="add-comment">
<a href="#add_comment_<?php the_ID(); ?>">
<i class="fa fa-comments-o"></i> <?php _e('Add a Comment', 'fansub'); ?>
</a>
</p>
<?php
}
}
function fansub_get_coupon_store($post_id = null) {
if(!fansub_id_number_valid($post_id)) {
$post_id = get_the_ID();
}
$term = new WP_Error();
if(has_term('', 'store', $post_id)) {
$terms = wp_get_post_terms($post_id, 'store');
$term = current($terms);
}
return $term;
}
function fansub_get_store_out_link($term) {
if(fansub_id_number_valid($term)) {
$term = get_term($term, 'store');
}
$url = '';
if(is_a($term, 'WP_Term')) {
$url = home_url('go-store/' . $term->slug);
}
return $url;
}
function fansub_get_coupon_out_url($post_id) {
if(is_a($post_id, 'WP_Post')) {
$post_id = $post_id->ID;
}
$url = home_url('out/' . $post_id);
return $url;
}
function fansub_get_store_by_slug($slug) {
return fansub_get_term_by_slug($slug, 'store');
}
$fansub_coupon_site = apply_filters('fansub_coupon_site', false);
if(!(bool)$fansub_coupon_site) {
return;
}
global $pagenow;
if('edit-tags.php' == $pagenow || 'term.php' == $pagenow) {
fansub_term_meta_different_name_field(array('store', 'coupon_cat'));
fansub_term_meta_thumbnail_field(array('store'));
$meta = new FANSUB_Meta('term');
$meta->set_taxonomies(array('store'));
$meta->add_field(array('id' => 'site', 'label' => __('Store URL', 'fansub')));
$meta->init();
}
if('post-new.php' == $pagenow || 'post.php' == $pagenow) {
fansub_meta_box_post_attribute(array('coupon'));
$meta = new FANSUB_Meta('post');
$meta->set_post_types(array('coupon'));
$meta->set_id('fansub_coupon_information');
$meta->set_title(__('Coupon Information', 'fansub'));
$meta->add_field(array('id' => 'percent_label', 'label' => __('Percent Label:', 'fansub')));
$meta->add_field(array('id' => 'text_label', 'label' => __('Text Label:', 'fansub')));
$meta->add_field(array('id' => 'coupon_code', 'label' => __('Code:', 'fansub')));
$meta->add_field(array('id' => 'expired_date', 'label' => __('Expires:', 'fansub'), 'field_callback' => 'fansub_field_datetime_picker', 'data_type' => 'timestamp', 'min_date' => 0, 'date_format' => 'm/d/Y'));
$meta->add_field(array('id' => 'url', 'label' => __('URL:', 'fansub')));
$meta->init();
}
function fansub_coupon_on_save_post($post_id) {
if(!fansub_can_save_post($post_id)) {
return;
}
$current_post = get_post($post_id);
if(!has_term('', 'coupon_type', $post_id) && !empty($current_post->post_title)) {
wp_set_object_terms($post_id, 'Promo Codes', 'coupon_type');
}
if('coupon' == $current_post->post_type) {
$event = fansub_get_method_value('event');
update_post_meta($post_id, 'event', $event);
}
}
add_action('save_post', 'fansub_coupon_on_save_post');
function fansub_coupon_update_post_class($classes) {
global $post;
if('coupon' == $post->post_type) {
$post_id = $post->ID;
$type = fansub_get_coupon_type($post_id);
$type = array_search(current($type), $type);
if(!empty($type)) {
$classes[] = 'coupon-type-' . $type;
if('code' == $type) {
$code = fansub_get_coupon_code($post_id);
if(empty($code)) {
$classes[] = 'coupon-no-code';
}
}
}
}
return $classes;
}
add_filter('post_class', 'fansub_coupon_update_post_class');
function fansub_coupon_on_init_hook() {
add_rewrite_endpoint('go-store', EP_ALL);
add_rewrite_endpoint('out', EP_ALL);
}
add_action('init', 'fansub_coupon_on_init_hook');
function fansub_coupon_on_wp_hook() {
$store = get_query_var('go-store');
if(!empty($store)) {
$term = fansub_get_store_by_slug($store);
if(is_a($term, 'WP_Term')) {
$url = fansub_get_store_url($term->term_id);
if(!empty($url)) {
wp_redirect($url);
exit;
} else {
wp_redirect(home_url('/'));
exit;
}
}
}
$out = get_query_var('out');
if(!empty($out)) {
$url = fansub_get_coupon_url($out);
if(!empty($url)) {
wp_redirect($url);
exit;
} else {
wp_redirect(home_url('/'));
exit;
}
}
}
add_action('wp', 'fansub_coupon_on_wp_hook');
function fansub_coupon_pre_get_posts($query) {
if($query->is_main_query()) {
if(is_tax('store')) {
$posts_per_page = apply_filters('fansub_archive_coupon_posts_per_page', 15);
$query->set('posts_per_page', $posts_per_page);
} elseif(is_search()) {
$query->set('post_type', 'coupon');
}
if(is_post_type_archive('coupon') || is_search() || is_tax('store') || is_tax('coupon_cat') || is_tax('coupon_tag')) {
$exclude_expired = apply_filters('fansub_exclude_expired_coupon', false);
if($exclude_expired) {
$query_vars = $query->query_vars;
$expired_coupon = (bool)fansub_get_value_by_key($query_vars, 'expired_coupon');
if(!$expired_coupon) {
$meta_query = fansub_get_value_by_key($query_vars, 'meta_query');
if(fansub_array_has_value($meta_query)) {
foreach($meta_query as $meta) {
if(fansub_array_has_value($meta)) {
foreach($meta as $child_meta) {
if(fansub_array_has_value($child_meta)) {
$key = fansub_get_value_by_key($child_meta, 'key');
$value = fansub_get_value_by_key($child_meta, 'value');
$compare = fansub_get_value_by_key($child_meta, 'compare');
if('expired_date' == $key && is_numeric($value) && '<' == $compare) {
$expired_coupon = true;
break;
}
}
}
}
}
}
}
if(!$expired_coupon) {
$current_date_time = fansub_get_current_date('m/d/Y');
$timestamp = current_time('timestamp', 0);
$meta_item = array(
'relation' => 'OR',
array(
'key' => 'expired_date',
'value' => $timestamp,
'type' => 'numeric',
'compare' => '>='
),
array(
'key' => 'expired_date',
'compare' => 'NOT EXISTS'
)
);
$args = array(
$meta_item
);
$query->set('meta_query', $args);
}
}
}
}
return $query;
}
if(!is_admin()) add_action('pre_get_posts', 'fansub_coupon_pre_get_posts');
function fansub_coupon_filter_ajax_callback() {
$result = array(
'have_posts' => false
);
$term = fansub_get_method_value('term');
$filter = fansub_get_method_value('filter');
if(fansub_id_number_valid($term)) {
$posts_per_page = fansub_get_method_value('posts_per_page');
$paged = fansub_get_method_value('paged');
$args = array(
'post_type' => 'coupon',
'posts_per_page' => $posts_per_page,
'paged' => $paged,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'store',
'field' => 'id',
'terms' => array($term)
)
)
);
$type_object = new WP_Error();
switch($filter) {
case 'coupon-code';
$type_object = fansub_get_coupon_type_object();
break;
case 'promotion':
$type_object = fansub_get_coupon_type_object('deal');
break;
}
if(is_a($type_object, 'WP_Term')) {
$tax_item = array(
'taxonomy' => 'coupon_type',
'field' => 'id',
'terms' => array($type_object->term_id)
);
$args = fansub_query_sanitize_tax_query($tax_item, $args);
}
$query = fansub_query($args);
$result['have_posts'] = $query->have_posts();
if($query->have_posts()) {
$html_data = '';
while($query->have_posts()) {
$query->the_post();
ob_start();
fansub_theme_get_loop('archive-coupon');
$html_data .= ob_get_clean();
}
wp_reset_postdata();
$result['html_data'] = $html_data;
}
}
echo json_encode($result);
exit;
}
add_action('wp_ajax_fansub_coupon_filter', 'fansub_coupon_filter_ajax_callback');
add_action('wp_ajax_nopriv_fansub_coupon_filter', 'fansub_coupon_filter_ajax_callback');
function fansub_coupon_attribute_meta_box_field($meta) {
if(!is_object($meta)) {
return;
}
global $post;
$meta_id = $post->post_type . '_attributes';
$meta_id = fansub_sanitize_id($meta_id);
if('coupon' == $post->post_type && $meta->get_id() == $meta_id) {
$query = fansub_query(array('post_type' => 'event', 'posts_per_page' => -1));
$all_option = '<option value=""></option>';
$selected = get_post_meta($post->ID, 'event', true);
foreach($query->posts as $qpost) {
$all_option .= fansub_field_get_option(array('value' => $qpost->ID, 'text' => $qpost->post_title, 'selected' => $selected));
}
$args = array(
'id' => 'event_chosen',
'name' => 'event',
'all_option' => $all_option,
'value' => $selected,
'class' => 'widefat',
'label' => fansub_uppercase_first_char_only('Event') . ':',
'placeholder' => __('Choose parent post', 'fansub')
);
fansub_field_select_chosen($args);
}
}
add_action('fansub_post_meta_box_field', 'fansub_coupon_attribute_meta_box_field');
if('post.php' == $pagenow || 'post-new.php' == $pagenow) {
add_filter('fansub_use_chosen_select', '__return_true');
}
if('options-permalink.php' == $pagenow || true) {
$data = get_option('fansub_permalink');
$option = new FANSUB_Option('', 'permalink');
$option->set_parent_slug('options-permalink.php');
$option->set_update_option(true);
$option->add_field(array('value' => fansub_get_value_by_key($data, 'coupon_store_base'), 'id' => 'coupon_store_base', 'title' => __('Coupon store base', 'fansub'), 'section' => 'optional', 'placeholder' => fansub_coupon_store_base()));
$option->add_field(array('value' => fansub_get_value_by_key($data, 'coupon_category_base'), 'id' => 'coupon_category_base', 'title' => __('Coupon category base', 'fansub'), 'section' => 'optional', 'placeholder' => fansub_coupon_category_base()));
$option->add_field(array('value' => fansub_get_value_by_key($data, 'coupon_tag_base'), 'id' => 'coupon_tag_base', 'title' => __('Coupon tag base', 'fansub'), 'section' => 'optional', 'placeholder' => fansub_coupon_tag_base()));
$option->add_field(array('value' => fansub_get_value_by_key($data, 'coupon_type_base'), 'id' => 'coupon_type_base', 'title' => __('Coupon type base', 'fansub'), 'section' => 'optional', 'placeholder' => fansub_coupon_type_base()));
$option->init();
}
function fansub_coupon_filter_taxonomy_base($base, $taxonomy) {
switch($taxonomy) {
case 'store':
$base = 'store';
break;
case 'coupon_cat':
$base = 'coupon_cat';
break;
}
return $base;
}
add_filter('fansub_remove_term_base_taxonomy_base', 'fansub_coupon_filter_taxonomy_base', 10, 2);

503
fansub/css/fansub-admin.css Normal file
View File

@ -0,0 +1,503 @@
/**
* Last updated: 21/04/2016
*/
/**
* Option form
*/
.fansub.term-field th,
.fansub .form-table th {
font-weight: 600;
line-height: 1.3;
padding: 20px 10px 20px 0;
text-align: left;
vertical-align: top;
width: 200px;
}
.fansub form input[type="radio"],
.fansub form input[type="checkbox"] {
display: inline-block;
margin-top: 0;
vertical-align: -5px;
}
.fansub.term-field td,
.fansub .form-table td {
line-height: 1.3;
margin-bottom: 9px;
padding: 15px 10px;
vertical-align: middle;
}
.fansub.option-page .form-table {
table-layout: fixed;
}
/**
* Widgets
*/
.fansub-widget .widefat {
display: block;
width: 100%;
}
.fansub-widget label + .media-preview img {
margin-top: 2px;
}
.fansub-fieldset {
border: 1px solid #ddd;
padding: 10px;
}
.fansub-fieldset legend {
line-height: 11px;
margin-left: 10px;
padding-left: 5px;
padding-right: 5px;
}
/**
* Meta box
*/
.fansub-meta-box label {
display: inline-block;
padding-right: 20px;
width: 20%;
}
.fansub-meta-box label.display-block {
display: block;
}
.fansub-meta-box label.full-width {
padding-right: 0;
width: auto;
}
.fansub-meta-box label.vertical-align-top {
vertical-align: top;
}
.fansub-meta-box textarea {
width: 65%;
}
.fansub-meta-box label:first-letter {
text-transform: uppercase;
}
.fansub-meta-box .meta-row {
padding: 10px 0;
}
.fansub-meta-box div.meta-row input[type="checkbox"],
.fansub-meta-box div.meta-row input[type="radio"] {
margin-top: 0;
}
.fansub-meta-box .fansub-field-group {
margin-bottom: 10px;
}
.fansub-meta-box input.regular-text {
max-width: 100%;
}
.fansub.server-information .postbox table {
table-layout: fixed;
width: 100%;
}
.fansub.server-information .postbox td {
padding: 5px 0;
width: 50%;
}
.fansub.server-information .postbox td.label {
vertical-align: top;
width: 30%;
}
.fansub.server-information .postbox td.label:after {
content: ":";
}
.form-field input[type="radio"] + label img.layout {
display: inline-block;
margin-bottom: 20px;
max-width: 215px;
vertical-align: top;
}
/**
* Option Page
*/
.fansub.option-page {
padding-top: 25px;
}
.fansub.option-page.has-sidebar > .page-title {
display: none;
}
.fansub.option-page .page-header {
background-color: #8ac843;
border-bottom: 3px solid #eb242b;
border-top-left-radius: 3px;
border-top-right-radius: 3px;
color: #fff;
height: 50px;
line-height: 50px;
margin-top: 5px;
padding: 15px;
}
.fansub.option-page .page-header .theme-name {
color: #fff;
float: left;
font-size: 23px;
margin: 0 15px 0 0;
}
.fansub.option-page .page-header .theme-version {
line-height: 55px;
opacity: 0.75;
}
.fansub.option-page .copyright {
text-align: center;
}
.fansub.option-page .copyright a {
text-decoration: none;
}
.fansub.option-page .page-content:not(.no-sidebar) {
background-color: #f3f3f3;
border-left: 1px solid #d5d5d5;
border-right: 1px solid #d5d5d5;
overflow: hidden;
}
.fansub.option-page .page-footer {
background-color: #eee;
border: 1px solid #d5d5d5;
border-top-color: #e7e7e7;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
padding: 10px;
}
.fansub.option-page .page-footer p {
color: #999;
margin: 0;
}
.fansub.option-page .page-content .sidebar {
float: left;
min-height: 100px;
position: relative;
width: 220px;
}
.fansub.option-page .page-content .sidebar + .main {
background-color: #fcfcfc;
border-left: 1px solid #d8d8d8;
box-sizing: border-box;
float: left;
min-height: 100px;
overflow: hidden;
padding: 0 20px;
width: calc(100% - 220px);
}
.fansub.option-page .page-content .sidebar .list-tabs {
margin: 10px 0 0;
padding: 0;
}
.fansub.option-page .page-content .sidebar .list-tabs li {
margin: 0;
}
.fansub.option-page .page-content .sidebar .list-tabs li a {
border-bottom: 1px solid #e7e7e7;
border-top: 1px solid #f9f9f9;
color: #555;
display: block;
padding: 10px 4px 10px 14px;
text-decoration: none;
}
.fansub.option-page .page-content .sidebar .list-tabs li:first-child {
border-top: 1px solid #e7e7e7;
}
.fansub.option-page .page-content .sidebar .list-tabs li:last-child {
border-bottom: 1px solid #f9f9f9;
}
.fansub.option-page .page-content .sidebar .list-tabs li.active a {
background-color: #fcfcfc;
border-left: 2px solid #8ac843;
border-right: 1px solid #fcfcfc;
box-shadow: none;
cursor: auto;
font-weight: 700;
margin-right: -1px;
outline: 0 none;
}
.fansub.option-page .page-content .sidebar .list-tabs li:not(.active):hover a {
background-color: #e5e5e5;
border-left: medium none;
cursor: pointer;
margin: 0;
}
.fansub.option-page .page-content .sidebar .list-tabs li,
.fansub.option-page .page-content .sidebar .list-tabs li a:focus,
.fansub.option-page .page-content .sidebar .list-tabs li a:active {
box-shadow: none;
outline: 0 none;
}
.fansub .plugin-card {
margin-left: 0;
margin-right: 0;
width: 100%;
}
#nav > h2::after {
clear: both;
content: "";
display: table;
}
/**
* Sortable
*/
.fansub-sortable {
background-color: #f5f5f5;
border: 1px solid #eaeaea;
float: left;
margin: 0 20px 0 0;
min-height: 200px;
padding: 10px;
width: 45%;
}
.fansub-sortable:nth-child(2) {
margin-right: 0;
}
.fansub-sortable.connected-result {
background-color: #fbf9ef;
border-color: #fcefa1;
}
.fansub-sortable.connected-result + input + .description,
.fansub-sortable.connected-result + .description {
clear: both;
padding-top: 5px;
}
.fansub-sortable li {
background-color: #eee;
border: 1px solid #ddd;
cursor: pointer;
margin-bottom: 10px;
padding: 10px;
}
.fansub-sortable li:last-child {
margin-bottom: 0;
}
.fansub-sortable li.ui-state-highlight {
background-color: #fcf8e3;
border-color: #ffee92;
}
/**
* Bootstrap
*/
.fansub .btn-warning {
background-color: #f0ad4e;
border-color: #eea236;
color: #fff;
}
.fansub div.bs-callout-warning,
.fansub .bs-callout-warning {
border-left-color: #aa6708;
}
.fansub div.bs-callout-danger,
.fansub .bs-callout-danger {
border-left-color: #ce4844;
}
.fansub div.bs-callout-info,
.fansub .bs-callout-info {
border-left-color: #1b809e;
}
.bs-callout-warning.notice.updated,
.bs-callout-warning.notice,
.bs-callout-warning.updated,
.bs-callout-warning {
border-left-color: #f0ad4e;
}
/**
* Media upload
*/
.fansub-meta-box .media-preview,
.fansub .media-preview,
.fansub-widget .media-preview {
display: block;
}
.fansub-meta-box .media-preview img,
.fansub-widget .media-preview img,
.fansub .media-preview img {
margin-bottom: 10px;
max-height: 150px;
max-width: 100%;
width: auto;
}
.fansub-widget .media-preview + input,
.fansub .media-preview + input {
display: inline-block;
height: 28px;
margin-right: 5px;
}
.fansub-widget .media-preview + input,
.fansub .media-preview + input {
max-width: 80%;
width: 60%;
}
.edit-tags-php .fansub .media-preview + input {
width: 60%;
}
.fansub-widget .media-preview + input {
width: 75%;
}
.fansub-widget .media-preview + input {
height: 29px;
}
.fansub-meta-box .media-preview img,
.fansub-widget .media-preview img {
max-height: 315px;
}
/**
* Chosen select
*/
.fansub-widget .chosen-container .chosen-choices {
background: #fff none repeat scroll 0 0;
border: 1px solid #ddd;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.07) inset;
padding: 2px 5px;
}
.fansub-widget .chosen-container-multi .chosen-choices li.search-choice {
background: #eee none repeat scroll 0 0;
border: 1px solid #ccc;
border-radius: 0;
}
.fansub-widget .fansub-widget-field {
margin: 1em 0;
}
.fansub-widget .fansub-widget-field label {
line-height: 1.5;
vertical-align: middle;
}
/**
* Recommended Plugins
*/
.fansub .wp-filter {
margin-bottom: 0;
}
.fansub .plugin-icon {
height: 128px;
left: 20px;
margin: 0 20px 20px 0;
position: absolute;
top: 20px;
width: 128px;
}
.fansub .widefat a {
text-decoration: none;
}
/**
* Table
*/
.wp-list-table .manage-column.column-featured,
.wp-list-table .manage-column.column-active {
text-align: center;
}
/**
* Menu item
*/
.fansub-custom-fields.menu-item-fields .description {
color: #666;
margin: 2px 0 5px;
}
.fansub-custom-fields.menu-item-fields label {
display: block;
font-style: italic;
}
.fansub-custom-fields.menu-item-fields .media-preview {
display: block;
}
.fansub-custom-fields.menu-item-fields input.media-url {
margin-right: 5px;
width: 70%;
}
.fansub-custom-fields.menu-item-fields .media-preview img {
background-color: #eee;
margin: 2px 0;
}
/**
* Utils
*/
.form-table .fansub-disconnect-social {
cursor: pointer;
}
.form-table .fansub-disconnect-social:hover {
opacity: 0.5;
}

1
fansub/css/fansub-admin.min.css vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

1
fansub/css/fansub-front-end.min.css vendored Normal file

File diff suppressed because one or more lines are too long

178
fansub/css/fansub-login.css Normal file
View File

@ -0,0 +1,178 @@
/**
* Last updated: 21/04/2016
*/
/**
* Global
*/
body.login.fansub {
background-color: #f1f1f1;
font-family: arial, lucinda, verdana, geneva, sans-serif;
}
body.login.fansub div#login h1 a {
background-image: none;
height: auto;
text-indent: inherit;
width: auto;
}
body.login.fansub div#login h1 a img {
max-height: 150px;
max-width: 100%;
width: auto;
}
body.login.fansub div#login {
padding-top: 2%;
}
body.login.fansub form label {
font-weight: 400;
}
body.login.fansub form input[type="radio"],
body.login.fansub form input[type="checkbox"] {
display: inline-block;
margin-top: 0;
vertical-align: -3px;
}
body.login.fansub form input[type="text"] {
width: 100%;
}
body.login.fansub form input.fansub-captcha-code {
width: 50%;
}
body.login.fansub #login form p.submit {
clear: both;
display: block;
height: auto;
overflow: hidden;
padding: 10px 0 0;
}
body.login.fansub #login form p.submit .btn,
body.login.fansub #login form p.submit .button {
clear: both;
display: block;
font-size: 16px;
height: auto;
letter-spacing: 1px;
margin: 0;
padding-bottom: 10px;
padding-top: 10px;
width: 100%;
}
body.fansub.login #backtoblog {
display:none
}
body.fansub.login #nav {
padding: 0;
}
body.fansub.login #nav {
color: rgba(0, 0, 0, 0);
}
body.fansub.login #nav a {
background-repeat: no-repeat;
background-size: 16px auto;
color: #33b5e6;
display: inline-block;
margin-right: 10px;
}
body.fansub.login #nav a {
background-image: url("../images/icon-login-16.png");
background-position: left 2px;
padding-left: 22px;
}
body.fansub.login #nav .lostpassword {
background-image: url("../images/icon-lost-password-24.png");
background-position: left center;
background-size: 16px auto;
padding-left: 22px;
}
body.fansub.login #nav .register {
background-image: url("../images/icon-register-16.png");
background-position: left 1px;
padding-left: 20px;
}
body.fansub.login input.fansub-captcha-code {
font-size: 13px;
}
.fansub.login form .btn-social-login {
color: #f7f7f7;
display: inline;
font-weight: 700;
margin: 0;
outline: 0 none;
transition: none 0s ease 0s ;
width: 100%;
}
.fansub.login form .btn-social-login [class*="flip"] {
display: inline-block;
fill: #f7f7f7;
font-size: 16px;
height: 18px;
line-height: 12px;
margin-right: 7px;
margin-top: -3px;
vertical-align: middle;
width: 18px;
}
.fansub.login #login form p.social-login {
margin-bottom: 15px;
}
.fansub .btn-ajax:focus,
.fansub .btn-ajax:active,
.fansub form .btn-ajax:focus,
.fansub form .btn-ajax:active,
.fansub form .btn-social-login:focus,
.fansub form .btn-social-login:active {
cursor: wait;
}
.fansub form button.btn-facebook {
background: rgba(0, 0, 0, 0) linear-gradient(to bottom, #3b5998 0px, #344e86 100%) repeat scroll 0 0;
border: 1px solid #344e86;
}
.fansub form .btn-social-login {
color: #f7f7f7;
display: inline;
font-weight: 700;
margin: 0;
outline: 0 none;
transition: none 0s ease 0s;
}
.fansub form button.btn-google {
background: #d14836 linear-gradient(to bottom, #dd4b39 0px, #d14836 100%) repeat scroll 0 0;
border: 1px solid #d14836;
}
.fansub form button.btn-google:hover {
background: #d14836 none repeat scroll 0 0;
border-color: #d14836;
transition: none 0s ease 0s;
}
.fansub form button.btn-facebook:hover {
background: #344e86 none repeat scroll 0 0;
border-color: #344e86;
transition: none 0s ease 0s;
}

1
fansub/css/fansub-login.min.css vendored Normal file
View File

@ -0,0 +1 @@
body.login.fansub{background-color:#f1f1f1;font-family:arial,lucinda,verdana,geneva,sans-serif}body.login.fansub div#login h1 a{background-image:none;height:auto;text-indent:inherit;width:auto}body.login.fansub div#login h1 a img{max-height:150px;max-width:100%;width:auto}body.login.fansub div#login{padding-top:2%}body.login.fansub form label{font-weight:400}body.login.fansub form input[type=radio],body.login.fansub form input[type=checkbox]{display:inline-block;margin-top:0;vertical-align:-3px}body.login.fansub form input[type=text]{width:100%}body.login.fansub form input.fansub-captcha-code{width:50%}body.login.fansub #login form p.submit{clear:both;display:block;height:auto;overflow:hidden;padding:10px 0 0}body.login.fansub #login form p.submit .btn,body.login.fansub #login form p.submit .button{clear:both;display:block;font-size:16px;height:auto;letter-spacing:1px;margin:0;padding-bottom:10px;padding-top:10px;width:100%}body.fansub.login #backtoblog{display:none}body.fansub.login #nav{padding:0;color:transparent}body.fansub.login #nav a{background-repeat:no-repeat;background-size:16px auto;color:#33b5e6;display:inline-block;margin-right:10px;background-image:url(../images/icon-login-16.png);background-position:left 2px;padding-left:22px}.fansub form .btn-social-login,.fansub.login form .btn-social-login{color:#f7f7f7;font-weight:700;outline:0;transition:none 0s ease 0s}body.fansub.login #nav .lostpassword{background-image:url(../images/icon-lost-password-24.png);background-position:left center;background-size:16px auto;padding-left:22px}body.fansub.login #nav .register{background-image:url(../images/icon-register-16.png);background-position:left 1px;padding-left:20px}body.fansub.login input.fansub-captcha-code{font-size:13px}.fansub.login form .btn-social-login{display:inline;margin:0;width:100%}.fansub.login form .btn-social-login [class*=flip]{display:inline-block;fill:#f7f7f7;font-size:16px;height:18px;line-height:12px;margin-right:7px;margin-top:-3px;vertical-align:middle;width:18px}.fansub.login #login form p.social-login{margin-bottom:15px}.fansub .btn-ajax:active,.fansub .btn-ajax:focus,.fansub form .btn-ajax:active,.fansub form .btn-ajax:focus,.fansub form .btn-social-login:active,.fansub form .btn-social-login:focus{cursor:wait}.fansub form button.btn-facebook{background:linear-gradient(to bottom,#3b5998 0,#344e86 100%) rgba(0,0,0,0);border:1px solid #344e86}.fansub form .btn-social-login{display:inline;margin:0}.fansub form button.btn-google{background:linear-gradient(to bottom,#dd4b39 0,#d14836 100%) #d14836;border:1px solid #d14836}.fansub form button.btn-google:hover{background:#d14836;border-color:#d14836;transition:none 0s ease 0s}.fansub form button.btn-facebook:hover{background:#344e86;border-color:#344e86;transition:none 0s ease 0s}

View File

@ -0,0 +1,30 @@
/**
* Last updated: 21/04/2016
*/
.fansub-maintenance {
background: #fff no-repeat fixed center center;
background-size: cover;
font-family: arial, Tahoma, sans-serif;
font-size: 200%;
line-height: 38px;
text-align: center;
}
.fansub-maintenance {
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
}
.fansub-maintenance .heading {
font-size: 50px;
margin-bottom: 25px;
margin-top: 150px;
}
.fansub-maintenance .site,
.fansub-maintenance .site .site-inner,
.fansub-maintenance .site .site-inner .site-content {
background: rgba(0, 0, 0, 0) none repeat scroll 0 0;
}

1
fansub/css/fansub-maintenance.min.css vendored Normal file
View File

@ -0,0 +1 @@
.fansub-maintenance{background:center center no-repeat fixed #fff;background-size:cover;font-family:arial,Tahoma,sans-serif;font-size:200%;line-height:38px;text-align:center;-webkit-background-size:cover;-moz-background-size:cover;-o-background-size:cover}.fansub-maintenance .heading{font-size:50px;margin-bottom:25px;margin-top:150px}.fansub-maintenance .site,.fansub-maintenance .site .site-inner,.fansub-maintenance .site .site-inner .site-content{background:rgba(0,0,0,0)}

513
fansub/css/fansub.css Normal file
View File

@ -0,0 +1,513 @@
/**
* Last updated: 21/04/2016
*/
/**
* Normalize
*/
html {
font-family: sans-serif;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}
body.fansub {
margin: 0;
}
.fansub article,
.fansub aside,
.fansub details,
.fansub figcaption,
.fansub figure,
.fansub footer,
.fansub header,
.fansub main,
.fansub menu,
.fansub nav,
.fansub section,
.fansub summary {
display: block;
}
.fansub audio,
.fansub canvas,
.fansub progress,
.fansub video {
display: inline-block;
vertical-align: baseline;
}
.fansub audio:not([controls]) {
display: none;
height: 0;
}
.fansub [hidden],
.fansub template {
display: none;
}
.fansub abbr[title] {
border-bottom: 1px dotted;
text-decoration: none;
}
.fansub b,
.fansub strong {
font-weight: 700;
}
.fansub dfn {
font-style: italic;
}
.fansub mark {
background: #ff0;
color: #000;
}
.fansub small {
font-size: 80%;
}
.fansub sub,
.fansub sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline;
}
.fansub sup {
top: -0.5em;
}
.fansub sub {
bottom: -0.25em;
}
.fansub img {
border: 0;
}
.fansub svg:not(:root) {
overflow: hidden;
}
.fansub figure {
margin: 0;
}
.fansub hr {
box-sizing: content-box;
height: 0;
}
.fansub pre {
overflow: auto;
}
.fansub code,
.fansub kbd,
.fansub pre,
.fansub samp {
font-family: monospace, monospace;
font-size: 1em;
}
.fansub button,
.fansub input,
.fansub optgroup,
.fansub select,
.fansub textarea {
color: inherit;
font: inherit;
margin: 0;
}
.fansub button,
.fansub select {
text-transform: none;
}
.fansub button {
overflow: visible;
}
.fansub button,
.fansub input,
.fansub select,
.fansub textarea {
max-width: 100%;
}
.fansub button,
.fansub html input[type="button"],
.fansub input[type="reset"],
.fansub input[type="submit"] {
-webkit-appearance: button;
cursor: pointer;
}
.fansub button[disabled],
.fansub html input[disabled] {
cursor: default;
opacity: .5;
}
.fansub button::-moz-focus-inner,
.fansub input::-moz-focus-inner {
border: 0;
padding: 0;
}
.fansub input {
line-height: normal;
}
.fansub input[type="checkbox"],
.fansub input[type="radio"] {
box-sizing: border-box;
margin-right: 0.4375em;
padding: 0;
}
.fansub input[type="number"]::-webkit-inner-spin-button,
.fansub input[type="number"]::-webkit-outer-spin-button {
height: auto;
}
.fansub input[type="search"] {
box-shadow: 0 1px 2px #eee inset;
-webkit-appearance: textfield;
}
.fansub input[type="search"]::-webkit-search-cancel-button,
.fansub input[type="search"]::-webkit-search-decoration {
-webkit-appearance: none;
}
.fansub fieldset {
border: 1px solid #e8e8e8;
margin: 0 0 1.75em;
padding: 0.875em;
}
.fansub fieldset > :last-child {
margin-bottom: 0;
}
.fansub legend {
border: 0 none;
display: inline-block;
margin: 0;
padding: 0 10px;
width: auto;
}
.fansub textarea {
overflow: auto;
vertical-align: top;
}
.fansub optgroup {
font-weight: 700;
}
.fansub table {
border-collapse: collapse;
border-spacing: 0;
}
/**
* Global
*/
.font-weight-normal {
font-weight: 400;
}
.fansub img {
height: auto;
max-width: 100%;
}
.fansub-widget .fansub-number.image-size,
.fansub-number.image-size {
display: inline-block;
max-width: 100px;
width: auto;
}
.fansub-number.image-size + span {
display: inline-block;
margin: 0 5px;
}
label.label-input-size {
display: inline-block;
margin-right: 10px;
}
.disabled {
box-shadow: none;
cursor: not-allowed;
opacity: 0.65;
pointer-events: none;
text-decoration: none;
}
.margin-top-10 {
margin-top: 10px;
}
.margin-bottom-10 {
margin-bottom: 10px;
}
.margin-top-15 {
margin-top: 15px;
}
.margin-bottom-15 {
margin-bottom: 15px;
}
.margin-top-20 {
margin-top: 20px;
}
.margin-bottom-20 {
margin-bottom: 20px;
}
.padding-top-10 {
padding-top: 10px;
}
.padding-bottom-10 {
padding-bottom: 10px;
}
.padding-top-15 {
padding-top: 15px;
}
.padding-bottom-15 {
padding-bottom: 15px;
}
.ajax-loading.full-page {
background-color: rgba(0, 0, 0, 0.5);
display: none;
height: 100%;
left: 0;
position: fixed;
top: 0;
width: 100%;
z-index: 9999;
}
.ajax-loading.full-page img {
background-color: #000;
border-radius: 10px;
box-sizing: content-box;
height: auto;
left: 50%;
margin-left: -16px;
margin-top: -16px;
padding: 20px;
position: relative;
top: 50%;
width: 32px;
}
.ajax-loading.full-page.active {
display: block;
}
.flip-horizontal {
-webkit-transform: scaleX(-1);
-moz-transform: scaleX(-1);
-ms-transform: scaleX(-1);
-o-transform: scaleX(-1);
transform: scaleX(-1);
}
.no-pointer-events {
pointer-events: none;
}
.fansub .noselect {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
/**
* Backgrounds
*/
.bg-success {
}
/**
* Buttons
*/
.fansub form .fansub-button,
.fansub .fansub-button {
border-radius: 3px;
display: inline-block;
line-height: 40px;
padding: 0 15px;
vertical-align: top;
}
.fansub .fansub-button.btn-grey,
.fansub form .fansub-button.btn-grey {
background: #e7e7e7 none repeat scroll 0 0;
color: #333;
}
/**
* Icons
*/
.icon-circle {
background-color: #ddd;
border-radius: 50%;
cursor: pointer;
display: inline-block;
height: 14px;
width: 14px;
}
.icon-circle-success {
background-color: #7ad03a;
}
.button img.fansub-icon,
button img.fansub-icon {
display: inline-block;
height: 18px;
margin-right: 5px;
padding: 0;
vertical-align: -4px;
width: 18px;
}
/*
* Upload
*/
input[type="file"].fansub-field-upload + .image-preview {
display: none;
margin-top: 10px;
}
input[type="file"].fansub-field-upload + .image-preview img {
border: 4px solid #ddd;
display: inline-block;
height: 140px;
margin-bottom: 15px;
margin-right: 15px;
width: 210px;
}
/*
* Modal
*/
.modal-dialog {
padding-top: 5%;
}
.admin-bar .modal-dialog {
padding-top: 6%;
}
.single-product.woocommerce .modal.product-fast-buy .modal-dialog {
padding-top: 2%;
}
@media only screen and (max-width: 780px) {
.admin-bar .modal-dialog {
padding-top: 15%;
}
.admin-bar.single-product.woocommerce .modal.product-fast-buy .modal-dialog {
padding-top: 15%;
}
}
@media only screen and (max-width: 360px) {
.admin-bar .modal-dialog {
padding-top: 15%;
}
.admin-bar.single-product.woocommerce .modal.product-fast-buy .modal-dialog {
padding-top: 15%;
}
}
/**
* Columns
*/
.col-xs-15,
.col-sm-15,
.col-md-15,
.col-lg-15 {
min-height: 1px;
padding-left: 10px;
padding-right: 10px;
position: relative;
}
.col-xs-15,
.col-sm-15,
.col-md-15,
.col-lg-15 {
float: left;
}
.col-xs-15 {
width: 20%;
}
@media (min-width: 768px) {
.col-sm-15 {
width: 20%;
}
}
@media (min-width: 992px) {
.col-md-15 {
width: 20%;
}
}
@media (min-width: 1200px) {
.col-lg-15 {
width: 20%;
}
}
/**
* Media Queries
*/
@-ms-viewport {
width: device-width;
}
@viewport {
width: device-width;
}

1
fansub/css/fansub.min.css vendored Normal file

File diff suppressed because one or more lines are too long

2
fansub/css/index.php Normal file
View File

@ -0,0 +1,2 @@
<?php
# Silence is golden.

BIN
fansub/fonts/Tahoma.ttf Normal file

Binary file not shown.

2
fansub/fonts/index.php Normal file
View File

@ -0,0 +1,2 @@
<?php
# Silence is golden.

415
fansub/front-end.php Normal file
View File

@ -0,0 +1,415 @@
<?php
if(!function_exists('add_filter')) exit;
function fansub_breadcrumb($args = array()) {
$before = fansub_get_value_by_key($args, 'before');
$after = fansub_get_value_by_key($args, 'after');
if(function_exists('yoast_breadcrumb') && fansub_wpseo_breadcrumb_enabled()) {
yoast_breadcrumb('<nav class="fansub-breadcrumb breadcrumb yoast clearfix">' . $before, $after . '</nav>');
return;
}
global $post;
$separator = isset($args['separator']) ? $args['separator'] : '/';
$breadcrums_id = isset($args['id']) ? $args['id'] : 'fansub_breadcrumbs';
$home_title = __('Home', 'fansub');
$custom_taxonomy = 'product_cat';
$class = isset($args['class']) ? $args['class'] : '';
$class = fansub_add_string_with_space_before($class, 'list-inline list-unstyled breadcrumbs');
if(!is_front_page()) {
echo '<div class="fansub-breadcrumb breadcrumb default clearfix">';
echo '<ul id="' . $breadcrums_id . '" class="' . $class . '">';
echo '<li class="item-home"><a class="bread-link bread-home" href="' . get_home_url() . '" title="' . $home_title . '">' . $home_title . '</a></li>';
echo '<li class="separator separator-home"> ' . $separator . ' </li>';
if(is_post_type_archive()) {
echo '<li class="item-current item-archive"><strong class="bread-current bread-archive">' . post_type_archive_title('', false) . '</strong></li>';
} elseif(is_archive() && is_tax() && !is_category()) {
$post_type = get_post_type();
if($post_type != 'post') {
$post_type_object = get_post_type_object($post_type);
$post_type_archive = get_post_type_archive_link($post_type);
if(is_object($post_type_object)) {
echo '<li class="item-cat item-custom-post-type-' . $post_type . '"><a class="bread-cat bread-custom-post-type-' . $post_type . '" href="' . $post_type_archive . '" title="' . $post_type_object->labels->name . '">' . $post_type_object->labels->name . '</a></li>';
echo '<li class="separator"> ' . $separator . ' </li>';
}
}
if(is_search()) {
echo '<li class="item-current item-current-' . get_search_query() . '"><strong class="bread-current bread-current-' . get_search_query() . '" title="Search results for: ' . get_search_query() . '">Search results for: ' . get_search_query() . '</strong></li>';
} else {
$custom_tax_name = get_queried_object()->name;
echo '<li class="item-current item-archive"><strong class="bread-current bread-archive">' . $custom_tax_name . '</strong></li>';
}
} elseif(is_single()) {
$post_type = get_post_type();
if($post_type != 'post') {
$post_type_object = get_post_type_object($post_type);
$post_type_archive = get_post_type_archive_link($post_type);
echo '<li class="item-cat item-custom-post-type-' . $post_type . '"><a class="bread-cat bread-custom-post-type-' . $post_type . '" href="' . $post_type_archive . '" title="' . $post_type_object->labels->name . '">' . $post_type_object->labels->name . '</a></li>';
echo '<li class="separator"> ' . $separator . ' </li>';
}
$category = get_the_category();
$array_values = array_values($category);
$last_category = end($array_values);
$get_cat_parents = '';
if(is_object($last_category)) {
$get_cat_parents = rtrim(get_category_parents($last_category->term_id, true, ','), ',');
}
$cat_parents = explode(',', $get_cat_parents);
$cat_display = '';
foreach($cat_parents as $parents) {
$cat_display .= '<li class="item-cat">' . $parents . '</li>';
$cat_display .= '<li class="separator"> ' . $separator . ' </li>';
}
$taxonomy_exists = taxonomy_exists($custom_taxonomy);
if(empty($last_category) && !empty($custom_taxonomy) && $taxonomy_exists) {
$taxonomy_terms = get_the_terms($post->ID, $custom_taxonomy);
if(isset($taxonomy_terms[0]) && is_a($taxonomy_terms[0], 'WP_Term')) {
$cat_id = $taxonomy_terms[0]->term_id;
$cat_nicename = $taxonomy_terms[0]->slug;
$cat_link = get_term_link($taxonomy_terms[0]->term_id, $custom_taxonomy);
$cat_name = $taxonomy_terms[0]->name;
}
}
if(!empty($last_category)) {
echo $cat_display;
echo '<li class="item-current item-' . $post->ID . '"><strong class="bread-current bread-' . $post->ID . '" title="' . get_the_title() . '">' . get_the_title() . '</strong></li>';
} elseif(!empty($cat_id)) {
echo '<li class="item-cat item-cat-' . $cat_id . ' item-cat-' . $cat_nicename . '"><a class="bread-cat bread-cat-' . $cat_id . ' bread-cat-' . $cat_nicename . '" href="' . $cat_link . '" title="' . $cat_name . '">' . $cat_name . '</a></li>';
echo '<li class="separator"> ' . $separator . ' </li>';
echo '<li class="item-current item-' . $post->ID . '"><strong class="bread-current bread-' . $post->ID . '" title="' . get_the_title() . '">' . get_the_title() . '</strong></li>';
} else {
echo '<li class="item-current item-' . $post->ID . '"><strong class="bread-current bread-' . $post->ID . '" title="' . get_the_title() . '">' . get_the_title() . '</strong></li>';
}
} elseif(is_category()) {
echo '<li class="item-current item-cat"><strong class="bread-current bread-cat">' . single_cat_title('', false) . '</strong></li>';
} elseif(is_page()) {
if($post->post_parent) {
$anc = get_post_ancestors($post->ID);
$anc = array_reverse($anc);
$anc = array_reverse($anc);
$parents = '';
foreach($anc as $ancestor) {
$parents .= '<li class="item-parent item-parent-' . $ancestor . '"><a class="bread-parent bread-parent-' . $ancestor . '" href="' . get_permalink($ancestor) . '" title="' . get_the_title($ancestor) . '">' . get_the_title($ancestor) . '</a></li>';
$parents .= '<li class="separator separator-' . $ancestor . '"> ' . $separator . ' </li>';
}
echo $parents;
echo '<li class="item-current item-' . $post->ID . '"><strong title="' . get_the_title() . '"> ' . get_the_title() . '</strong></li>';
} else {
echo '<li class="item-current item-' . $post->ID . '"><strong class="bread-current bread-' . $post->ID . '"> ' . get_the_title() . '</strong></li>';
}
} elseif(is_tag()) {
$term_id = get_query_var('tag_id');
$taxonomy = 'post_tag';
$args ='include=' . $term_id;
$terms = fansub_get_terms($taxonomy, $args);
if(fansub_array_has_value($terms)) {
echo '<li class="item-current item-tag-' . $terms[0]->term_id . ' item-tag-' . $terms[0]->slug . '"><strong class="bread-current bread-tag-' . $terms[0]->term_id . ' bread-tag-' . $terms[0]->slug . '">' . $terms[0]->name . '</strong></li>';
}
} elseif(is_day()) {
echo '<li class="item-year item-year-' . get_the_time('Y') . '"><a class="bread-year bread-year-' . get_the_time('Y') . '" href="' . get_year_link(get_the_time('Y')) . '" title="' . get_the_time('Y') . '">' . get_the_time('Y') . ' Archives</a></li>';
echo '<li class="separator separator-' . get_the_time('Y') . '"> ' . $separator . ' </li>';
echo '<li class="item-month item-month-' . get_the_time('m') . '"><a class="bread-month bread-month-' . get_the_time('m') . '" href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '" title="' . get_the_time('M') . '">' . get_the_time('M') . ' Archives</a></li>';
echo '<li class="separator separator-' . get_the_time('m') . '"> ' . $separator . ' </li>';
echo '<li class="item-current item-' . get_the_time('j') . '"><strong class="bread-current bread-' . get_the_time('j') . '"> ' . get_the_time('jS') . ' ' . get_the_time('M') . ' Archives</strong></li>';
} elseif(is_month()) {
echo '<li class="item-year item-year-' . get_the_time('Y') . '"><a class="bread-year bread-year-' . get_the_time('Y') . '" href="' . get_year_link(get_the_time('Y')) . '" title="' . get_the_time('Y') . '">' . get_the_time('Y') . ' Archives</a></li>';
echo '<li class="separator separator-' . get_the_time('Y') . '"> ' . $separator . ' </li>';
echo '<li class="item-month item-month-' . get_the_time('m') . '"><strong class="bread-month bread-month-' . get_the_time('m') . '" title="' . get_the_time('M') . '">' . get_the_time('M') . ' Archives</strong></li>';
} elseif(is_year()) {
echo '<li class="item-current item-current-' . get_the_time('Y') . '"><strong class="bread-current bread-current-' . get_the_time('Y') . '" title="' . get_the_time('Y') . '">' . get_the_time('Y') . ' Archives</strong></li>';
} elseif(is_author()) {
global $author;
$userdata = get_userdata($author);
echo '<li class="item-current item-current-' . $userdata->user_nicename . '"><strong class="bread-current bread-current-' . $userdata->user_nicename . '" title="' . $userdata->display_name . '">' . 'Author: ' . $userdata->display_name . '</strong></li>';
} elseif(get_query_var('paged')) {
echo '<li class="item-current item-current-' . get_query_var('paged') . '"><strong class="bread-current bread-current-' . get_query_var('paged') . '" title="Page ' . get_query_var('paged') . '">'.__('Page') . ' ' . get_query_var('paged') . '</strong></li>';
} elseif(is_search()) {
echo '<li class="item-current item-current-' . get_search_query() . '"><strong class="bread-current bread-current-' . get_search_query() . '" title="Search results for: ' . get_search_query() . '">Search results for: ' . get_search_query() . '</strong></li>';
} elseif(is_404()) {
echo '<li>' . __('Error 404', 'fansub') . '</li>';
}
echo '</ul>';
echo '</div>';
}
}
function fansub_facebook_login_button() {
$action = fansub_get_method_value('action', 'request');
?>
<button type="button" data-action="login-facebook" onclick="fansub_facebook_login();" class="btn-facebook btn-social-login btn btn-large">
<svg class="flicon-facebook flip-icon" viewBox="0 0 256 448" height="448" width="256" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" version="1.1">
<path d="M239.75 3v66h-39.25q-21.5 0-29 9t-7.5 27v47.25h73.25l-9.75 74h-63.5v189.75h-76.5v-189.75h-63.75v-74h63.75v-54.5q0-46.5 26-72.125t69.25-25.625q36.75 0 57 3z"/>
</svg>
<span>
<?php
if('register' == $action) {
fansub_text('Đăng ký bằng Facebook', __('Register with Facebook', 'fansub'));
} else {
fansub_text('Đăng nhập bằng Facebook', __('Login with Facebook', 'fansub'));
}
?>
</span>
</button>
<?php
}
function fansub_google_login_button() {
$action = fansub_get_method_value('action', 'request');
?>
<button type="button" data-action="login-google" onclick="fansub_google_login();" class="btn-google btn-social-login btn btn-large">
<svg class="flicon-google flip-icon" viewBox="0 0 30 28" height="448" width="256" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" version="1.1">
<path d="M 17.471,2c0,0-6.28,0-8.373,0C 5.344,2, 1.811,4.844, 1.811,8.138c0,3.366, 2.559,6.083, 6.378,6.083 c 0.266,0, 0.524-0.005, 0.776-0.024c-0.248,0.475-0.425,1.009-0.425,1.564c0,0.936, 0.503,1.694, 1.14,2.313 c-0.481,0-0.945,0.014-1.452,0.014C 3.579,18.089,0,21.050,0,24.121c0,3.024, 3.923,4.916, 8.573,4.916 c 5.301,0, 8.228-3.008, 8.228-6.032c0-2.425-0.716-3.877-2.928-5.442c-0.757-0.536-2.204-1.839-2.204-2.604 c0-0.897, 0.256-1.34, 1.607-2.395c 1.385-1.082, 2.365-2.603, 2.365-4.372c0-2.106-0.938-4.159-2.699-4.837l 2.655,0 L 17.471,2z M 14.546,22.483c 0.066,0.28, 0.103,0.569, 0.103,0.863c0,2.444-1.575,4.353-6.093,4.353 c-3.214,0-5.535-2.034-5.535-4.478c0-2.395, 2.879-4.389, 6.093-4.354c 0.75,0.008, 1.449,0.129, 2.083,0.334 C 12.942,20.415, 14.193,21.101, 14.546,22.483z M 9.401,13.368c-2.157-0.065-4.207-2.413-4.58-5.246 c-0.372-2.833, 1.074-5.001, 3.231-4.937c 2.157,0.065, 4.207,2.338, 4.58,5.171 C 13.004,11.189, 11.557,13.433, 9.401,13.368zM 26,8L 26,2L 24,2L 24,8L 18,8L 18,10L 24,10L 24,16L 26,16L 26,10L 32,10L 32,8 z"/>
</svg>
<span>
<?php
if('register' == $action) {
fansub_text('Đăng ký bằng Google', __('Register with Google', 'fansub'));
} else {
fansub_text('Đăng nhập bằng Google', __('Login with Google', 'fansub'));
}
?>
</span>
</button>
<?php
}
function fansub_entry_meta_terms($args = array()) {
$taxonomy = fansub_get_value_by_key($args, 'taxonomy', 'category');
if(empty($taxonomy)) {
return;
}
$meta_class = 'entry-terms';
fansub_add_string_with_space_before($meta_class, 'tax-' . fansub_sanitize_html_class($taxonomy));
$icon = fansub_get_value_by_key($args, 'icon', '<i class="fa fa-list-alt icon-left"></i>');
$before = fansub_get_value_by_key($args, 'before', '<span class="' . $meta_class . '">');
$after = fansub_get_value_by_key($args, 'after', '</span>');
$post_id = fansub_get_value_by_key($args, 'post_id', get_the_ID());
$separator = fansub_get_value_by_key($args, 'separator', ', ');
the_terms($post_id, $taxonomy, $before . $icon, $separator, $after);
}
function fansub_the_date() {
?>
<time datetime="<?php the_time('c'); ?>" itemprop="datePublished" class="entry-time published date post-date"><?php echo get_the_date(); ?></time>
<?php
}
function fansub_the_comment_link() {
$post_id = get_the_ID();
if(comments_open($post_id)) {
$comment_count = fansub_get_post_comment_count($post_id);
$comment_text = $comment_count . ' Bình luận';
?>
<span class="entry-comments-link">
<a href="<?php the_permalink(); ?>#comments"><?php echo $comment_text; ?></a>
</span>
<?php
}
}
function fansub_the_author($args = array()) {
$before = fansub_get_value_by_key($args, 'before');
$author_url = fansub_get_author_posts_url();
?>
<span itemtype="http://schema.org/Person" itemscope itemprop="author" class="entry-author vcard author post-author">
<?php if(!empty($before)) : ?>
<span class="before-text"><?php echo $before; ?></span>
<?php endif; ?>
<span class="fn">
<a rel="author" itemprop="url" class="entry-author-link" href="<?php echo $author_url; ?>"><span itemprop="name" class="entry-author-name"><?php the_author(); ?></span></a>
</span>
</span>
<?php
}
function fansub_entry_meta($args = array()) {
$post_id = fansub_get_value_by_key($args, 'post_id', get_the_ID());
$class = fansub_get_value_by_key($args, 'class');
if(!isset($args['taxonomy'])) {
$args['taxonomy'] = '';
}
$cpost = get_post($post_id);
if(!is_a($cpost, 'WP_Post')) {
return;
}
$author_url = fansub_get_author_posts_url();
$comment_count = fansub_get_post_comment_count($post_id);
$comment_text = $comment_count . ' Bình luận';
fansub_add_string_with_space_before($class, 'entry-meta');
$show_date = fansub_get_value_by_key($args, 'show_date', true);
$show_updated = fansub_get_value_by_key($args, 'show_updated', true);
$show_author = fansub_get_value_by_key($args, 'show_author', true);
$show_term = fansub_get_value_by_key($args, 'show_term', false);
$show_comment = fansub_get_value_by_key($args, 'show_comment', true);
?>
<p class="<?php echo $class; ?>">
<?php if($show_date) : ?>
<?php fansub_the_date(); ?>
<?php endif; ?>
<?php if($show_updated) : ?>
<time datetime="<?php the_modified_time('c'); ?>" itemprop="dateModified" class="entry-modified-time date modified post-date"><?php the_modified_date(); ?></time>
<?php endif; ?>
<?php if($show_author) : ?>
<?php fansub_the_author(); ?>
<?php endif; ?>
<?php
if($show_term) {
$meta_term_args = $args;
$term_icon = fansub_get_value_by_key($args, 'term_icon');
if(!empty($term_icon)) {
$meta_term_args['icon'] = $term_icon;
}
fansub_entry_meta_terms($meta_term_args);
}
?>
<?php if($show_comment && comments_open($post_id)) : ?>
<?php fansub_the_comment_link(); ?>
<?php endif; ?>
<?php if(current_theme_supports('fansub-schema')) : ?>
<?php
global $authordata;
$author_id = 0;
$author_name = '';
$author_avatar = '';
if(fansub_object_valid($authordata)) {
$author_id = $authordata->ID;
$author_name = $authordata->display_name;
$author_avatar = get_avatar_url($author_id, array('size' => 128));
}
$logo_url = apply_filters('fansub_publisher_logo_url', '');
?>
<span itemprop="publisher" itemscope itemtype="https://schema.org/Organization" class="small hidden">
<span itemprop="logo" itemscope itemtype="https://schema.org/ImageObject">
<img alt="" src="<?php echo $logo_url; ?>">
<meta itemprop="url" content="<?php echo $logo_url; ?>">
<meta itemprop="width" content="600">
<meta itemprop="height" content="60">
</span>
<meta itemprop="name" content="<?php echo $author_name; ?>">
</span>
<?php endif; ?>
</p>
<?php
}
function fansub_entry_meta_author_first($args = array()) {
$post_id = fansub_get_value_by_key($args, 'post_id', get_the_ID());
$class = fansub_get_value_by_key($args, 'class');
$cpost = get_post($post_id);
if(!is_a($cpost, 'WP_Post')) {
return;
}
$author_url = fansub_get_author_posts_url();
$comment_count = fansub_get_post_comment_count($post_id);
$comment_text = $comment_count . ' Bình luận';
fansub_add_string_with_space_before($class, 'entry-meta');
?>
<p class="<?php echo $class; ?>">
<span itemtype="http://schema.org/Person" itemscope itemprop="author" class="entry-author vcard author post-author">
<span class="fn">
<a rel="author" itemprop="url" class="entry-author-link" href="<?php echo $author_url; ?>"><span itemprop="name" class="entry-author-name"><?php the_author(); ?></span></a>
</span>
</span>
<time datetime="<?php the_time('c'); ?>" itemprop="datePublished" class="entry-time published date post-date"><?php echo get_the_date(); ?></time>
<time datetime="<?php the_modified_time('c'); ?>" itemprop="dateModified" class="entry-modified-time date modified post-date"><?php the_modified_date(); ?></time>
<?php if(comments_open($post_id)) : ?>
<span class="entry-comments-link">
<a href="<?php the_permalink(); ?>#comments"><?php echo $comment_text; ?></a>
</span>
<?php endif; ?>
<?php if(current_theme_supports('fansub-schema')) : ?>
<?php
global $authordata;
$author_id = 0;
$author_name = '';
$author_avatar = '';
if(fansub_object_valid($authordata)) {
$author_id = $authordata->ID;
$author_name = $authordata->display_name;
$author_avatar = get_avatar_url($author_id, array('size' => 128));
}
$logo_url = apply_filters('fansub_publisher_logo_url', '');
?>
<span itemprop="publisher" itemscope itemtype="https://schema.org/Organization" class="small hidden">
<span itemprop="logo" itemscope itemtype="https://schema.org/ImageObject">
<img alt="" src="<?php echo $logo_url; ?>">
<meta itemprop="url" content="<?php echo $logo_url; ?>">
<meta itemprop="width" content="600">
<meta itemprop="height" content="60">
</span>
<meta itemprop="name" content="<?php echo $author_name; ?>">
</span>
<?php endif; ?>
</p>
<?php
}
function fansub_rel_canonical() {
if(!is_singular() || has_action('wp_head', 'rel_canonical')) {
return;
}
global $wp_the_query;
if(!$id = $wp_the_query->get_queried_object_id()) {
return;
}
$link = get_permalink($id);
if($page = get_query_var('cpage')) {
$link = get_comments_pagenum_link($page);
}
$link = apply_filters('fansub_head_rel_canonical', $link, $id);
echo "<link rel='canonical' href='$link' />\n";
}
function fansub_posts_pagination($args = array()) {
$defaults = array(
'prev_text' => __('Trước', 'fansub'),
'next_text' => __('Tiếp theo', 'fansub'),
'screen_reader_text' => __('Phân trang', 'fansub')
);
$args = wp_parse_args($args, $defaults);
the_posts_pagination($args);
}
function fansub_entry_content($content = '') {
?>
<div class="entry-content" itemprop="text">
<?php
if(!empty($content)) {
echo wpautop($content);
} else {
the_content();
}
?>
</div>
<?php
}
function fansub_entry_summary() {
echo '<div class="entry-summary" itemprop="text">';
the_excerpt();
echo '</div>';
}
function fansub_entry_tags() {
echo '<div class="entry-tags">';
the_tags('<span class="tag-label"><i class="fa fa-tag icon-left"></i><span class="text">Tags:</span></span>&nbsp;', ' ', '');
echo '</div>';
}
function fansub_button_vote_group() {
$post_id = get_the_ID();
$vote_up = absint(get_post_meta($post_id, 'likes', true));
$vote_down = absint(fansub_get_post_meta('dislikes', $post_id));
?>
<div class="text-center vote-buttons">
<p class="vote btn-group" data-post-id="<?php the_ID(); ?>">
<a class="btn btn-default vote-up vote-post" data-vote-type="up" data-vote="<?php echo $vote_up; ?>">
<i class="fa fa-thumbs-o-up"></i>
</a>
<a class="btn btn-default vote-down vote-post" data-vote-type="down" data-vote="<?php echo $vote_down; ?>">
<i class="fa fa-thumbs-o-down"></i>
</a>
</p>
</div>
<?php
}

3015
fansub/functions.php Normal file

File diff suppressed because it is too large Load Diff

1343
fansub/html-field.php Normal file

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 774 B

BIN
fansub/images/grey.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 258 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 771 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 755 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 508 B

2
fansub/images/index.php Normal file
View File

@ -0,0 +1,2 @@
<?php
# Silence is golden.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 B

BIN
fansub/images/white.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 B

2
fansub/index.php Normal file
View File

@ -0,0 +1,2 @@
<?php
# Silence is golden.

315
fansub/js/fansub-admin.js Normal file
View File

@ -0,0 +1,315 @@
/**
* Last updated: 07/05/2016
*/
window.fansub = window.fansub || {};
window.wp = window.wp || {};
jQuery(document).ready(function($) {
var $body = $('body');
fansub.addBulkAction = function(actions) {
actions = actions || [];
for(var i = 0; i < actions.length; i++) {
$('<option>').val(actions[i][0]).text(actions[i][1]).appendTo("select[name='action']");
$('<option>').val(actions[i][0]).text(actions[i][1]).appendTo("select[name='action2']");
}
};
fansub.widgetPostTypeChange = function(element) {
var $element = $(element),
selected = $element.val(),
$fansub_widget = $element.closest('.fansub-widget'),
$select_category = $fansub_widget.find('.select-category'),
$select_category_container = $select_category.closest('.fansub-widget-field-group');
if('category' == selected) {
$select_category_container.fadeIn(500);
} else {
$select_category_container.fadeOut();
}
};
(function() {
if($body.hasClass('widgets-php')) {
$(document).on('widget-updated', function(event, widget) {
var widget_id = widget[0].id;
if(widget_id && widget_id.match('fansub')) {
var $widget = $(this);
if(widget_id.match('fansub_widget_banner') || widget_id.match('fansub_widget_icon')) {
$widget.find('.btn-insert-media').live('click', function(e) {
e.preventDefault();
fansub.mediaUpload($(this));
});
$widget.find('.btn-remove').live('click', function(e) {
e.preventDefault();
var $container = $(this).parent();
fansub.mediaUpload($container.find('.btn-insert-media'), {remove: true});
});
$widget.find('input.media-url').live('change input', function(e) {
e.preventDefault();
var $container = $(this).parent();
fansub.mediaUpload($container.find('.btn-insert-media'), {change: true});
});
} else if(widget_id.match('fansub_widget_post')) {
$widget.find('.fansub-widget-post .get-by').on('change', function(e) {
e.preventDefault();
fansub.widgetPostTypeChange(this);
});
}
}
});
$('div.widgets-sortables').bind('sortreceive', function(event, ui) {
var widget_id = $(ui.item).attr('id');
if(widget_id && widget_id.match('fansub')) {
var $widget = $(ui.item);
if(widget_id.match('fansub_widget_banner') || widget_id.match('fansub_widget_icon')) {
$widget.find('.btn-insert-media').live('click', function(e) {
e.preventDefault();
fansub.mediaUpload($(this));
});
} else if(widget_id.match('fansub_widget_post')) {
$widget.find('.fansub-widget-post .get-by').on('change', function(e) {
e.preventDefault();
fansub.widgetPostTypeChange(this);
});
}
}
}).bind('sortstop', function(event, ui) {
var widget_id = $(ui.item).attr('id');
if(widget_id && widget_id.match('fansub')) {
var $widget = $(ui.item);
if(widget_id.match('fansub_widget_post')) {
$widget.find('.fansub-widget-post .get-by').on('change', function(e) {
e.preventDefault();
fansub.widgetPostTypeChange(this);
});
}
}
});
$(document).ajaxSuccess(function(e, xhr, settings) {
if(settings.data.search('action=save-widget') != -1) {
if(settings.data.search('fansub') != -1) {
var id_base = fansub.getParamByName(settings.data, 'id_base'),
$widget = $(this);
if('fansub_widget_post' == id_base || 'fansub_widget_top_commenter' == id_base || 'fansub_widget_term' == id_base) {
$widget.find('.fansub-widget .chosen-container').hide();
$widget.find('.fansub-widget .chooseable').fansubChosenSelect();
$widget.find('.fansub-widget .chosen-container').show();
}
}
}
});
$(document).delegate('.btn-insert-media', 'click', function(e) {
e.preventDefault();
fansub.mediaUpload($(this));
});
}
})();
(function() {
$('.fansub-widget-post .get-by').live('change', function(e) {
e.preventDefault();
fansub.widgetPostTypeChange(this);
});
})();
(function() {
var $sortable = $('.sortable');
if($sortable.length) {
$sortable.fansubSortable();
}
})();
(function() {
$('#fansub_plugin_license_use_for').on('change', function(e) {
e.preventDefault();
var $element = $(this),
$customer_email = $('#fansub_plugin_license_customer_email'),
$license_code = $('#fansub_plugin_license_license_code');
$customer_email.val('');
$license_code.val('');
$.ajax({
type: 'POST',
dataType: 'json',
url: fansub.ajax_url,
data: {
action: 'fansub_fetch_plugin_license',
use_for: $element.val()
},
success: function(response){
$customer_email.val(response.customer_email);
$license_code.val(response.license_code);
}
});
});
})();
(function() {
$('.fansub input[type="checkbox"]').on('click', function(e) {
var $element = $(this),
value = $element.val();
if($element.is(':checked')) {
if(1 != value) {
$element.val(1);
}
} else {
if(1 == value || '' == value) {
$element.val(0);
}
}
});
})();
(function() {
fansub.switcherAjax();
})();
(function() {
if($body.hasClass('post-php') || $body.hasClass('post-new-php')) {
fansub.addDefaultQuicktagButton();
}
})();
(function() {
var $choseables = $('.fansub-widget .chooseable');
if($choseables.length) {
$choseables.fansubChosenSelect();
}
$choseables = $('.fansub-meta-box .chooseable');
if($choseables.length) {
$choseables.fansubChosenSelect();
}
})();
(function() {
var $color_picker = $('.fansub-color-picker'),
$datetime_picker = $('.fansub-datetime-picker');
if($color_picker.length) {
$color_picker.wpColorPicker();
}
if($datetime_picker.length) {
var options = {},
min_date = $datetime_picker.attr('data-min-date'),
date_format = $datetime_picker.attr('data-date-format');
if($.isNumeric(min_date)) {
options.minDate = 0;
}
if($.trim(date_format)) {
options.dateFormat = date_format;
}
$datetime_picker.datepicker(options);
}
})();
(function() {
$('.fansub.server-information .postbox > .handlediv').on('click', function(e) {
e.preventDefault();
var $element = $(this),
$postbox = $element.parent();
$postbox.toggleClass('closed');
if($postbox.hasClass('closed')) {
$element.attr('aria-expanded', 'false');
} else {
$element.attr('aria-expanded', 'true');
}
});
})();
(function() {
var $fansub_option_page = $('.fansub.option-page');
if($fansub_option_page.length) {
var $sidebar = $fansub_option_page.find('.sidebar'),
$main = $fansub_option_page.find('.main-content');
if($sidebar.height() >= $main.height()) {
$main.css({'min-height' : $sidebar.height() + 50 + 'px'});
}
}
})();
(function() {
$('.fansub-field-maps').fansubGoogleMaps();
var $category_list = $('.classifieds.fansub-google-maps #categorychecklist, .classifieds #classifieds_typechecklist, .classifieds #classifieds_objectchecklist, .classifieds #pricechecklist, .classifieds #acreagechecklist');
$category_list.find('input[type="checkbox"]').on('change', function() {
var $element = $(this),
checked = $element.is(':checked'),
$list_item = $element.closest('ul');
$list_item.find('input[type="checkbox"]').attr('checked', false);
if(checked) {
$element.attr('checked', true);
}
});
})();
});
jQuery(document).ready(function($) {
(function() {
var $body = $('body');
if($body.hasClass('tools_page_fansub_developers')) {
var $compress_button = $('#fansub_developers_compress_css_js'),
$compress_css = $('#fansub_developers_compress_css'),
$compress_js = $('#fansub_developers_compress_js'),
$recompress = $('#fansub_developers_re_compress'),
$force_compress = $('#fansub_developers_force_compress'),
force_compress = false;
if($compress_button.length) {
$compress_button.on('click', function() {
var type = [];
if($compress_css.is(':checked')) {
type.push('css');
}
if($compress_js.is(':checked')) {
type.push('js');
}
if($recompress.is(':checked')) {
type.push('recompress');
}
if($force_compress.is(':checked')) {
force_compress = true;
}
$body.css({cursor: 'wait'});
alert('All your files are compressing, please wait...');
$.ajax({
type: 'POST',
dataType: 'json',
url: fansub.ajax_url,
data: {
action: 'fansub_compress_style_and_script',
type: JSON.stringify(type),
force_compress: force_compress
},
success: function(response){
$body.css({cursor: 'auto'});
alert('These files compressed successfully!');
}
});
});
}
}
})();
(function() {
$('.form-table .fansub-disconnect-social').on('click', function(e) {
e.preventDefault();
var $element = $(this),
user_id = $element.attr('data-user-id'),
social = $element.attr('data-social');
if(confirm(fansub.i18n.disconnect_confirm_message)) {
$.ajax({
type: 'POST',
dataType: 'json',
url: fansub.ajax_url,
data: {
action: 'fansub_disconnect_social_account',
social: social,
user_id: user_id
},
success: function(response){
window.location.href = window.location.href;
}
});
}
});
})();
});

1
fansub/js/fansub-admin.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,358 @@
/**
* Last updated: 20/04/2016
*/
jQuery(document).ready(function($) {
var $body = $('body');
(function() {
$('.sf-menu, .fansub-superfish-menu > ul').each(function() {
var $element = $(this),
options = {
hoverClass: 'sf-hover',
delay: 100,
cssArrows: false,
dropShadows: false
};
if(!$element.hasClass('sf-menu')) {
$element.addClass('sf-menu');
}
if($element.hasClass('slide')) {
options.animation = {
height: 'show',
marginTop: 'show',
marginBottom: 'show',
paddingTop: 'show',
paddingBottom: 'show'
};
options.animationOut = {
height: 'hide',
marginTop: 'hide',
marginBottom: 'hide',
paddingTop: 'hide',
paddingBottom: 'hide'
};
}
if($element.hasClass('arrow')) {
options.cssArrows = true;
}
$element.superfish(options);
});
})();
(function() {
$('.fansub-go-top').fansubScrollTop();
})();
(function() {
$('input[type="file"].fansub-field-upload').each(function() {
fansub.limitUploadFile($(this));
});
})();
(function() {
$('.fansub .comment-tools .comment-likes').on('click', function(e) {
e.preventDefault();
var $element = $(this),
$container = $element.closest('.comment'),
$count = $element.find('.count'),
comment_id = parseInt($container.attr('data-comment-id')),
likes = parseInt($element.attr('data-likes'));
$element.addClass('disabled');
$element.css({'text-decoration' : 'none'});
$.ajax({
type: 'POST',
dataType: 'json',
url: fansub.ajax_url,
data: {
action: 'fansub_comment_likes',
comment_id: comment_id,
likes: likes
},
success: function(response){
likes++;
$element.attr('data-likes', likes);
$count.html(response.likes);
}
});
return false;
});
$('.fansub .comment-tools .comment-report').on('click', function(e) {
e.preventDefault();
var $element = $(this),
$container = $element.closest('.comment'),
comment_id = parseInt($container.attr('data-comment-id'));
$element.addClass('disabled');
$element.css({'text-decoration' : 'none'});
$.ajax({
type: 'POST',
dataType: 'json',
url: fansub.ajax_url,
data: {
action: 'fansub_comment_report',
comment_id: comment_id
},
success: function(response){
}
});
return false;
});
$('.fansub .comment-tools .comment-share').on('click', function(e) {
e.preventDefault();
var $element = $(this);
$element.css({'text-decoration' : 'none'});
$element.toggleClass('active');
return false;
});
$('.fansub .comment-tools .comment-share .list-share .fa').on('click', function(e) {
e.preventDefault();
var $element = $(this);
$element.css({'text-decoration' : 'none'});
window.open($element.attr('data-url'), 'ShareWindow', 'height=450, width=550, toolbar=0, location=0, menubar=0, directories=0, scrollbars=0');
});
})();
(function() {
fansub.iconChangeCaptchaExecute();
})();
(function() {
$('.fansub.fansub-google-maps .fansub-field-maps').fansubGoogleMaps();
})();
(function() {
$('.vote .vote-post').on('click', function(e) {
e.preventDefault();
var $element = $(this),
$parent = $element.parent(),
vote_type = $element.attr('data-vote-type'),
post_id = $parent.attr('data-post-id');
$element.addClass('disabled');
$.ajax({
type: 'POST',
dataType: 'json',
url: fansub.ajax_url,
data: {
action: 'fansub_vote_post',
post_id: post_id,
vote_type: vote_type,
value: $element.attr('data-vote')
},
success: function(response){
if(response.success) {
$element.attr('data-vote', response.value);
$parent.addClass('disabled');
}
}
});
});
})();
(function() {
var $cart_preview = $('#fansubCart');
if($cart_preview.length) {
$cart_preview.on('click', '.fansub-post .fa-remove', function(e) {
e.preventDefault();
var $element = $(this),
post_id = $element.attr('data-id'),
$item = $element.closest('.fansub-post'),
$cart_contents = $element.closest('.fansub-cart-contents');
$element.addClass('disabled');
$.ajax({
type: 'POST',
dataType: 'json',
url: fansub.ajax_url,
data: {
action: 'fansub_wc_remove_cart_item',
post_id: post_id
},
success: function(response){
$item.fadeOut();
$item.remove();
if(response.updated) {
$cart_contents.html(response.cart_contents);
}
}
});
});
}
})();
// Tab widget
(function() {
var $tabber_widgets = $('.fansub-tabber-widget');
if($tabber_widgets.length) {
$tabber_widgets.each(function() {
var $element = $(this),
$list_tabs = $element.find('ul.nav-tabs');
$element.find('.tab-item').each(function() {
var widget = $(this).attr('id');
$(this).find('a.tab-title').attr('href', '#' + widget).wrap('<li></li>').parent().detach().appendTo($list_tabs);
});
$list_tabs.find('li:first').addClass('active');
$list_tabs.fadeIn();
$element.find('.tab-pane:first').addClass('active');
});
$tabber_widgets.on('click', '.nav-tabs li a', function(e) {
e.preventDefault();
var $element = $(this),
id = $element.attr('href').replace('#', ''),
$widget = $element.closest('.fansub-tabber-widget'),
$pane = $widget.find('div[id^="' + id + '"]');
$widget.find('.tab-pane').removeClass('active');
$pane.addClass('active');
});
}
})();
// Product fast buy
(function() {
var $modal = $('.single-product.woocommerce .modal.product-fast-buy');
if($modal.length) {
$modal.on('click', '.customer-info form button', function(e) {
e.preventDefault();
var $element = $(this),
$modal_body = $element.closest('.modal-body'),
$attributes_form = $modal_body.find('.attributes-form'),
attributes = [],
$form = $element.closest('form'),
$full_name = $form.find('.full-name'),
$phone = $form.find('.phone'),
$email = $form.find('.email'),
$address = $form.find('.address'),
$message = $form.find('.message');
if($full_name.prop('required') && !$.trim($full_name.val())) {
$full_name.focus();
} else if($phone.prop('required') && !$.trim($phone.val())) {
$phone.focus();
} else if($email.prop('required') && !$.trim($email.val())) {
$email.focus();
} else if($address.prop('required') && !$.trim($address.val())) {
$address.focus();
} else if($message.prop('required') && !$.trim($message.val())) {
$message.focus();
} else {
$element.addClass('disabled');
if($attributes_form.length) {
$attributes_form.find('select').each(function() {
var $select = $(this),
attribute = {name: $select.attr('data-attribute_name'), value: $select.val()};
attributes.push(attribute);
});
}
$.ajax({
type: 'POST',
dataType: 'json',
url: fansub.ajax_url,
data: {
action: 'fansub_wc_order_item',
post_id: $element.attr('data-id'),
name: $full_name.val(),
phone: $phone.val(),
email: $email.val(),
message: $message.val(),
address: $address.val(),
attributes: attributes
},
success: function(response){
if($.trim(response.html_data)) {
$modal_body.html(response.html_data);
}
}
});
}
});
}
})();
// User subscribe widget
(function() {
var $fansub_widget_subscribe = $('.fansub-subscribe-widget');
if($fansub_widget_subscribe.length) {
$fansub_widget_subscribe.find('.fansub-subscribe-form').on('submit', function(e) {
e.preventDefault();
var $element = $(this),
$messages = $element.find('.messages'),
use_captcha = $element.attr('data-captcha'),
register = $element.attr('data-register'),
$submit = $element.find('input[type="submit"]'),
$email = $element.find('.input-email'),
$name = $element.find('.input-name'),
$phone = $element.find('.input-phone'),
$captcha = $element.find('.fansub-captcha-code'),
captcha = '';
if($name.length && $name.prop('required') && !$.trim($name.val())) {
$name.focus();
} else if($phone.length && $phone.prop('required') && !$.trim($phone.val())) {
$phone.focus();
} else if($email.length && $email.prop('required') && !$.trim($email.val())) {
$email.focus();
} else if($captcha.length && $captcha.prop('required') && !$.trim($captcha.val())) {
$captcha.focus();
} else {
if($captcha.length) {
captcha = $captcha.val();
}
$submit.addClass('disabled');
$element.find('.img-loading').show();
$.ajax({
type: 'POST',
dataType: 'json',
url: fansub.ajax_url,
data: {
action: 'fansub_widget_subscribe',
name: $name.val(),
phone: $phone.val(),
email: $email.val(),
use_captcha: use_captcha,
captcha: captcha,
register: register
},
success: function(response){
$element.find('.img-loading').hide();
$captcha.next().next().trigger('click');
$messages.html(response.message);
if(response.success) {
} else {
$submit.removeClass('disabled');
}
}
});
}
});
}
})();
(function() {
$('.fansub').on('click', '.save-post, .favorite-post, .interest-post, .love-post', function(e) {
e.preventDefault();
if($body.hasClass('fansub-user')) {
var $element = $(this),
post_id = $element.attr('data-post-id');
$element.addClass('disabled');
$.ajax({
type: 'POST',
dataType: 'json',
url: fansub.ajax_url,
data: {
action: 'fansub_favorite_post',
post_id: post_id
},
success: function(response){
if(response.success) {
$element.html(response.html_data);
$element.removeClass('disabled');
}
}
});
} else {
window.location.href = fansub.login_url;
}
});
})();
});

1
fansub/js/fansub-front-end.min.js vendored Normal file

File diff suppressed because one or more lines are too long

25
fansub/js/fansub-login.js Normal file
View File

@ -0,0 +1,25 @@
/**
* Last updated: 20/04/2016
*/
jQuery(document).ready(function($) {
(function() {
var logo_url = fansub.login_logo_url;
if(fansub.isImageUrl(logo_url)) {
$('.login #login > h1 a').html(fansub.createImageHTML({src: logo_url}));
}
$('form .submit .button').attr('class', 'btn btn-warning');
})();
(function(){
$('#nav').find('a').each(function(){
var that = $(this),
action = fansub.getParamByName(that.attr('href'), 'action');
that.addClass(action);
});
})();
(function() {
fansub.iconChangeCaptchaExecute();
})();
});

1
fansub/js/fansub-login.min.js vendored Normal file
View File

@ -0,0 +1 @@
jQuery(document).ready(function(n){!function(){var a=fansub.login_logo_url;fansub.isImageUrl(a)&&n(".login #login > h1 a").html(fansub.createImageHTML({src:a})),n("form .submit .button").attr("class","btn btn-warning")}(),function(){n("#nav").find("a").each(function(){var a=n(this),t=fansub.getParamByName(a.attr("href"),"action");a.addClass(t)})}(),function(){fansub.iconChangeCaptchaExecute()}()});

View File

@ -0,0 +1,33 @@
/**
* Last updated: 25/02/2016
*/
window.fansub = window.fansub || {};
jQuery(document).ready(function($) {
tinymce.create('tinymce.plugins.fansub_shortcode_plugin', {
init: function(ed, url) {
ed.addCommand('fansub_insert_shortcode', function() {
var selected = tinyMCE.activeEditor.selection.getContent(),
content = '';
});
var shortcode_values = [],
shortcodes_button = fansub.shortcodes;
$.each(shortcodes_button, function(key, i) {
shortcode_values.push({text: key, value: key});
});
ed.addButton('fansub_shortcode', {
type: 'listbox',
text: 'Shortcodes',
title: 'Insert shortcode',
cmd: 'fansub_insert_shortcode',
onselect: function(e) {
var selected = tinyMCE.activeEditor.selection.getContent(),
shortcode = e.control.settings.value;
tinyMCE.activeEditor.selection.setContent('[' + shortcode + ']' + selected + '[/' + shortcode + ']');
},
values: shortcode_values
});
}
});
tinymce.PluginManager.add('fansub_shortcode', tinymce.plugins.fansub_shortcode_plugin);
});

View File

@ -0,0 +1 @@
window.fansub=window.fansub||{},jQuery(document).ready(function(t){tinymce.create("tinymce.plugins.fansub_shortcode_plugin",{init:function(o,e){o.addCommand("fansub_insert_shortcode",function(){tinyMCE.activeEditor.selection.getContent()});var n=[],c=fansub.shortcodes;t.each(c,function(t,o){n.push({text:t,value:t})}),o.addButton("fansub_shortcode",{type:"listbox",text:"Shortcodes",title:"Insert shortcode",cmd:"fansub_insert_shortcode",onselect:function(t){var o=tinyMCE.activeEditor.selection.getContent(),e=t.control.settings.value;tinyMCE.activeEditor.selection.setContent("["+e+"]"+o+"[/"+e+"]")},values:n})}}),tinymce.PluginManager.add("fansub_shortcode",tinymce.plugins.fansub_shortcode_plugin)});

1376
fansub/js/fansub.js Normal file

File diff suppressed because it is too large Load Diff

1
fansub/js/fansub.min.js vendored Normal file

File diff suppressed because one or more lines are too long

2
fansub/js/index.php Normal file
View File

@ -0,0 +1,2 @@
<?php
# Silence is golden.

146
fansub/language.php Normal file
View File

@ -0,0 +1,146 @@
<?php
if(!function_exists('add_filter')) exit;
function fansub_qtranslate_x_installed() {
return defined('QTX_VERSION');
}
function fansub_qtranslate_x_admin_sections($sections) {
$sections['fansub_string_translation'] = __('String Translation', 'fansub');
return $sections;
}
function fansub_qtranslate_x_admin_section_field() {
qtranxf_admin_section_start('fansub_string_translation');
echo '<br>';
$table = new FANSUB_Table_String_Translation(fansub_get_all_mo_posts());
$table->prepare_items();
$table->search_box(__('Search translations', 'fansub'), 'translations');
$table->display();
fansub_field_input_hidden(array('id' => 'fansub_action', 'value' => 'string_translation'));
qtranxf_admin_section_end('fansub_string_translation');
}
if(fansub_qtranslate_x_installed()) {
add_filter('qtranslate_admin_sections', 'fansub_qtranslate_x_admin_sections');
add_action('qtranslate_configuration', 'fansub_qtranslate_x_admin_section_field');
}
function fansub_get_all_mo_posts($args = array()) {
$defaults = array(
'post_type' => 'fansub_mo',
'posts_per_page' => -1
);
$args = wp_parse_args($args, $defaults);
$query = fansub_query($args);
return $query->posts;
}
function fansub_get_qtranslate_x_config() {
return $GLOBALS['q_config'];
}
function fansub_get_qtranslate_x_enabled_languages() {
return qtranxf_getSortedLanguages();
}
function fansub_get_registered_string_language() {
$strings = get_option('fansub_string_translations');
if(!is_array($strings)) {
$strings = array();
}
$strings = apply_filters('fansub_registered_string_language', $strings);
return $strings;
}
function fansub_get_active_registered_string_language() {
global $fansub_active_registered_string_translations;
if(!is_array(($fansub_active_registered_string_translations))) {
$fansub_active_registered_string_translations = array();
}
return apply_filters('fansub_active_registered_string_language', $fansub_active_registered_string_translations);
}
function fansub_register_string_language($args = array()) {
if(!did_action('init')) {
_doing_it_wrong(__FUNCTION__, __('Please call this function in <strong>fansub_register_string_translation</strong> hook.', 'fansub'), FANSUB_VERSION);
return;
}
$name = fansub_get_value_by_key($args, 'name');
$string = fansub_get_value_by_key($args, 'string');
$context = fansub_get_value_by_key($args, 'context', 'HocWP');
$multiline = fansub_get_value_by_key($args, 'multiline');
$key = md5($string);
$active_strings = fansub_get_active_registered_string_language();
$active_strings[$key]['name'] = $name;
$active_strings[$key]['string'] = $string;
$active_strings[$key]['context'] = $context;
$active_strings[$key]['multiline'] = $multiline;
$GLOBALS['fansub_active_registered_string_translations'] = $active_strings;
$transient_name = 'fansub_string_translation_registered_' . serialize($args);
if(false === get_transient($transient_name)) {
$strings = fansub_get_registered_string_language();
$strings[$key]['name'] = $name;
$strings[$key]['string'] = $string;
$strings[$key]['context'] = $context;
$strings[$key]['multiline'] = $multiline;
update_option('fansub_string_translations', $strings);
$mo = new FANSUB_MO();
$post_id = $mo->export_to_db($string);
if(fansub_id_number_valid($post_id)) {
set_transient($transient_name, $post_id, WEEK_IN_SECONDS);
}
}
}
function fansub_translate_x_string_transaltion_update() {
if(isset($_REQUEST['fansub_action'])) {
$search = fansub_get_method_value('s', 'request');
$strings = fansub_get_method_value('strings');
if(fansub_array_has_value($strings)) {
$mo = new FANSUB_MO();
$saved_strings = fansub_get_registered_string_language();
foreach($strings as $encrypted_string) {
unset($saved_strings[$encrypted_string]);
$mo->delete_from_db($encrypted_string, true);
}
update_option('fansub_string_translations', $saved_strings);
fansub_delete_transient('fansub_string_translation_registered');
}
$args = array_intersect_key($_REQUEST, array_flip(array('s', 'paged', 'group')));
if(!empty($search)) {
$args['s'] = $search;
}
if(!empty($args['s'])) {
$args['s'] = urlencode($args['s']);
}
$translations = fansub_get_method_value('translation');
if(fansub_array_has_value($translations)) {
foreach($translations as $key => $value) {
if(!empty($value)) {
$mo = fansub_get_post_by_column('post_title', 'fansub_mo_' . $key, OBJECT, array('post_type' => 'fansub_mo'));
if(is_a($mo, 'WP_Post')) {
$obj = new FANSUB_MO($mo->ID);
$obj->export_to_db($mo->post_excerpt, $value);
}
}
}
}
$url = add_query_arg($args, wp_get_referer());
wp_safe_redirect($url);
exit;
}
}
add_action('admin_init', 'fansub_translate_x_string_transaltion_update');
function fansub_language_register_hook() {
do_action('fansub_register_string_translation');
}
add_action('wp_loaded', 'fansub_language_register_hook');
function fansub_language_admin_enqueue_scripts($hook) {
if('settings_page_qtranslate-x' == $hook) {
add_filter('fansub_use_admin_style_and_script', '__return_true');
}
}
add_action('admin_enqueue_scripts', 'fansub_language_admin_enqueue_scripts');

15
fansub/lib.php Normal file
View File

@ -0,0 +1,15 @@
<?php
if(!function_exists('add_filter')) exit;
function fansub_lib_load_chosen() {
wp_enqueue_script('chosen', FANSUB_URL . '/lib/chosen/chosen.jquery.min.js', array('jquery'), false, true);
wp_enqueue_style('chosen-style', FANSUB_URL . '/lib/chosen/chosen.min.css');
}
function fansub_lib_admin_style_and_script() {
global $pagenow;
$use_chosen_select = apply_filters('fansub_use_chosen_select', false);
if('widgets.php' == $pagenow || $use_chosen_select) {
fansub_lib_load_chosen();
}
}
add_action('admin_enqueue_scripts', 'fansub_lib_admin_style_and_script');

View File

@ -0,0 +1,844 @@
<?php
/*
* bfi_thumb - WP Image Resizer v1.3
*
* (c) 2013 Benjamin F. Intal / Gambit
*
* 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 <http://www.gnu.org/licenses/>.
*/
/** Uses WP's Image Editor Class to resize and filter images
*
* @param $url string the local image URL to manipulate
* @param $params array the options to perform on the image. Keys and values supported:
* 'width' int pixels
* 'height' int pixels
* 'opacity' int 0-100
* 'color' string hex-color #000000-#ffffff
* 'grayscale' bool
* 'negate' bool
* 'crop' bool
* 'crop_only' bool
* 'crop_x' bool string
* 'crop_y' bool string
* 'crop_width' bool string
* 'crop_height' bool string
* 'quality' int 1-100
* @param $single boolean, if false then an array of data will be returned
* @return string|array containing the url of the resized modified image
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! function_exists( 'bfi_thumb' ) ) {
function bfi_thumb( $url, $params = array(), $single = true ) {
$class = BFI_Class_Factory::getNewestVersion( 'BFI_Thumb' );
return call_user_func( array( $class, 'thumb' ), $url, $params, $single );
}
}
/**
* Class factory, this is to make sure that when multiple bfi_thumb scripts
* are used (e.g. a plugin and a theme both use it), we always use the
* latest version.
*/
if ( ! class_exists( 'BFI_Class_Factory' ) ) {
class BFI_Class_Factory {
public static $versions = array();
public static $latestClass = array();
public static function addClassVersion( $baseClassName, $className, $version ) {
if ( empty( self::$versions[ $baseClassName ] ) ) {
self::$versions[ $baseClassName ] = array();
}
self::$versions[ $baseClassName ][] = array(
'class' => $className,
'version' => $version
);
}
public static function getNewestVersion( $baseClassName ) {
if ( empty( self::$latestClass[ $baseClassName ] ) ) {
usort( self::$versions[ $baseClassName ], array( __CLASS__, "versionCompare" ) );
self::$latestClass[ $baseClassName ] = self::$versions[ $baseClassName ][0]['class'];
unset( self::$versions[ $baseClassName ] );
}
return self::$latestClass[ $baseClassName ];
}
public static function versionCompare( $a, $b ) {
return version_compare( $a['version'], $b['version'] ) == 1 ? -1 : 1;
}
}
}
/*
* Change the default image editors
*/
add_filter( 'wp_image_editors', 'bfi_wp_image_editor' );
// Instead of using the default image editors, use our extended ones
if ( ! function_exists( 'bfi_wp_image_editor' ) ) {
function bfi_wp_image_editor( $editorArray ) {
// Make sure that we use the latest versions
return array(
BFI_Class_Factory::getNewestVersion( 'BFI_Image_Editor_GD' ),
BFI_Class_Factory::getNewestVersion( 'BFI_Image_Editor_Imagick' ),
);
}
}
/*
* Include the WP Image classes
*/
require_once ABSPATH . WPINC . '/class-wp-image-editor.php';
require_once ABSPATH . WPINC . '/class-wp-image-editor-imagick.php';
require_once ABSPATH . WPINC . '/class-wp-image-editor-gd.php';
/**
* check for ImageMagick or GD
*/
add_action( 'admin_init', 'bfi_wp_image_editor_check' );
if ( ! function_exists( 'bfi_wp_image_editor_check' ) ) {
function bfi_wp_image_editor_check() {
$arg = array( 'mime_type' => 'image/jpeg' );
if ( wp_image_editor_supports( $arg ) !== true ) {
add_filter( 'admin_notices', 'bfi_wp_image_editor_check_notice' );
}
}
}
if ( ! function_exists( 'bfi_wp_image_editor_check_notice' ) ) {
function bfi_wp_image_editor_check_notice() {
printf( "<div class='error'><p>%s</div>",
__( "The server does not have ImageMagick or GD installed and/or enabled! Any of these libraries are required for WordPress to be able to resize images. Please contact your server administrator to enable this before continuing.", "default" ) );
}
}
/*
* Enhanced Imagemagick Image Editor
*/
if ( ! class_exists( 'BFI_Image_Editor_Imagick_1_3' ) ) {
BFI_Class_Factory::addClassVersion( 'BFI_Image_Editor_Imagick', 'BFI_Image_Editor_Imagick_1_3', '1.3' );
class BFI_Image_Editor_Imagick_1_3 extends WP_Image_Editor_Imagick {
/** Changes the opacity of the image
*
* @supports 3.5.1
* @access public
*
* @param float $opacity (0.0-1.0)
* @return boolean|WP_Error
*/
public function opacity( $opacity ) {
$opacity /= 100;
try {
// From: http://stackoverflow.com/questions/3538851/php-imagick-setimageopacity-destroys-transparency-and-does-nothing
// preserves transparency
//$this->image->setImageOpacity($opacity);
return $this->image->evaluateImage( Imagick::EVALUATE_MULTIPLY, $opacity, Imagick::CHANNEL_ALPHA );
} catch ( Exception $e ) {
return new WP_Error( 'image_opacity_error', $e->getMessage() );
}
}
/** Tints the image a different color
*
* @supports 3.5.1
* @access public
*
* @param string hex color e.g. #ff00ff
* @return boolean|WP_Error
*/
public function colorize( $hexColor ) {
try {
return $this->image->colorizeImage( $hexColor, 1.0 );
} catch ( Exception $e ) {
return new WP_Error( 'image_colorize_error', $e->getMessage() );
}
}
/** Makes the image grayscale
*
* @supports 3.5.1
* @access public
*
* @return boolean|WP_Error
*/
public function grayscale() {
try {
return $this->image->modulateImage( 100, 0, 100 );
} catch ( Exception $e ) {
return new WP_Error( 'image_grayscale_error', $e->getMessage() );
}
}
/** Negates the image
*
* @supports 3.5.1
* @access public
*
* @return boolean|WP_Error
*/
public function negate() {
try {
return $this->image->negateImage( false );
} catch ( Exception $e ) {
return new WP_Error( 'image_negate_error', $e->getMessage() );
}
}
}
}
/*
* Enhanced GD Image Editor
*/
if ( ! class_exists( 'BFI_Image_Editor_GD_1_3' ) ) {
BFI_Class_Factory::addClassVersion( 'BFI_Image_Editor_GD', 'BFI_Image_Editor_GD_1_3', '1.3' );
class BFI_Image_Editor_GD_1_3 extends WP_Image_Editor_GD {
/** Rotates current image counter-clockwise by $angle.
* Ported from image-edit.php
* Added presevation of alpha channels
*
* @since 3.5.0
* @access public
*
* @param float $angle
* @return boolean|WP_Error
*/
public function rotate( $angle ) {
if ( function_exists('imagerotate') ) {
$rotated = imagerotate( $this->image, $angle, 0 );
// Add alpha blending
imagealphablending( $rotated, true );
imagesavealpha( $rotated, true );
if ( is_resource( $rotated ) ) {
imagedestroy( $this->image );
$this->image = $rotated;
$this->update_size();
return true;
}
}
return new WP_Error( 'image_rotate_error', __( 'Image rotate failed.', 'default' ), $this->file );
}
/** Changes the opacity of the image
*
* @supports 3.5.1
* @access public
*
* @param float $opacity (0.0-1.0)
* @return boolean|WP_Error
*/
public function opacity( $opacity ) {
$opacity /= 100;
$filtered = $this->_opacity( $this->image, $opacity );
if ( is_resource( $filtered ) ) {
// imagedestroy($this->image);
$this->image = $filtered;
return true;
}
return new WP_Error( 'image_opacity_error', __('Image opacity change failed.', 'default' ), $this->file );
}
// from: http://php.net/manual/en/function.imagefilter.php
// params: image resource id, opacity (eg. 0.0-1.0)
protected function _opacity( $image, $opacity ) {
if ( ! function_exists( 'imagealphablending' ) ||
! function_exists( 'imagecolorat' ) ||
! function_exists( 'imagecolorallocatealpha' ) ||
! function_exists( 'imagesetpixel' ) ) {
return false;
}
// get image width and height
$w = imagesx( $image );
$h = imagesy( $image );
// turn alpha blending off
imagealphablending( $image, false );
// find the most opaque pixel in the image (the one with the smallest alpha value)
$minalpha = 127;
for ( $x = 0; $x < $w; $x++ ) {
for ( $y = 0; $y < $h; $y++ ) {
$alpha = ( imagecolorat( $image, $x, $y ) >> 24 ) & 0xFF;
if ( $alpha < $minalpha ) {
$minalpha = $alpha;
}
}
}
// loop through image pixels and modify alpha for each
for ( $x = 0; $x < $w; $x++ ) {
for ( $y = 0; $y < $h; $y++ ) {
// get current alpha value (represents the TANSPARENCY!)
$colorxy = imagecolorat( $image, $x, $y );
$alpha = ( $colorxy >> 24 ) & 0xFF;
// calculate new alpha
if ( $minalpha !== 127 ) {
$alpha = 127 + 127 * $opacity * ( $alpha - 127 ) / ( 127 - $minalpha );
} else {
$alpha += 127 * $opacity;
}
// get the color index with new alpha
$alphacolorxy = imagecolorallocatealpha( $image, ( $colorxy >> 16 ) & 0xFF, ( $colorxy >> 8 ) & 0xFF, $colorxy & 0xFF, $alpha );
// set pixel with the new color + opacity
if( ! imagesetpixel( $image, $x, $y, $alphacolorxy ) ) {
return false;
}
}
}
imagesavealpha( $image, true );
return $image;
}
/** Tints the image a different color
*
* @supports 3.5.1
* @access public
*
* @param string hex color e.g. #ff00ff
* @return boolean|WP_Error
*/
public function colorize( $hexColor ) {
if ( function_exists( 'imagefilter' ) &&
function_exists( 'imagesavealpha' ) &&
function_exists( 'imagealphablending' ) ) {
$hexColor = preg_replace( '#^\##', '', $hexColor );
$r = hexdec( substr( $hexColor, 0, 2 ) );
$g = hexdec( substr( $hexColor, 2, 2 ) );
$b = hexdec( substr( $hexColor, 2, 2 ) );
imagealphablending( $this->image, false );
if ( imagefilter( $this->image, IMG_FILTER_COLORIZE, $r, $g, $b, 0 ) ) {
imagesavealpha( $this->image, true );
return true;
}
}
return new WP_Error( 'image_colorize_error', __( 'Image color change failed.', 'default' ), $this->file );
}
/** Makes the image grayscale
*
* @supports 3.5.1
* @access public
*
* @return boolean|WP_Error
*/
public function grayscale() {
if ( function_exists( 'imagefilter' ) ) {
if ( imagefilter( $this->image, IMG_FILTER_GRAYSCALE ) ) {
return true;
}
}
return new WP_Error( 'image_grayscale_error', __( 'Image grayscale failed.', 'default' ), $this->file );
}
/** Negates the image
*
* @supports 3.5.1
* @access public
*
* @return boolean|WP_Error
*/
public function negate() {
if ( function_exists( 'imagefilter' ) ) {
if ( imagefilter( $this->image, IMG_FILTER_NEGATE ) ) {
return true;
}
}
return new WP_Error( 'image_negate_error', __( 'Image negate failed.', 'default' ), $this->file );
}
}
}
/*
* Main Class
*/
if ( ! class_exists( 'BFI_Thumb_1_3' ) ) {
BFI_Class_Factory::addClassVersion( 'BFI_Thumb', 'BFI_Thumb_1_3', '1.3' );
class BFI_Thumb_1_3 {
/** Uses WP's Image Editor Class to resize and filter images
* Inspired by: https://github.com/sy4mil/Aqua-Resizer/blob/master/aq_resizer.php
*
* @param $url string the local image URL to manipulate
* @param $params array the options to perform on the image. Keys and values supported:
* 'width' int pixels
* 'height' int pixels
* 'opacity' int 0-100
* 'color' string hex-color #000000-#ffffff
* 'grayscale' bool
* 'crop' bool
* 'negate' bool
* 'crop_only' bool
* 'crop_x' bool string
* 'crop_y' bool string
* 'crop_width' bool string
* 'crop_height' bool string
* 'quality' int 1-100
* @param $single boolean, if false then an array of data will be returned
* @return string|array
*/
public static function thumb( $url, $params = array(), $single = true ) {
extract( $params );
//validate inputs
if ( ! $url ) {
return false;
}
$crop_only = isset( $crop_only ) ? $crop_only : false;
//define upload path & dir
$upload_info = wp_upload_dir();
$upload_dir = $upload_info['basedir'];
$upload_url = $upload_info['baseurl'];
$theme_url = get_template_directory_uri();
$theme_dir = get_template_directory();
// find the path of the image. Perform 2 checks:
// #1 check if the image is in the uploads folder
if ( strpos( $url, $upload_url ) !== false ) {
$rel_path = str_replace( $upload_url, '', $url );
$img_path = $upload_dir . $rel_path;
// #2 check if the image is in the current theme folder
} else if ( strpos( $url, $theme_url ) !== false ) {
$rel_path = str_replace( $theme_url, '', $url );
$img_path = $theme_dir . $rel_path;
}
// Fail if we can't find the image in our WP local directory
if ( empty( $img_path ) ) {
return $url;
}
// check if img path exists, and is an image indeed
if( ! @file_exists( $img_path ) || ! getimagesize( $img_path ) ) {
return $url;
}
// This is the filename
$basename = basename( $img_path );
//get image info
$info = pathinfo( $img_path );
$ext = $info['extension'];
list( $orig_w, $orig_h ) = getimagesize( $img_path );
// support percentage dimensions. compute percentage based on
// the original dimensions
if ( isset( $width ) ) {
if ( stripos( $width, '%' ) !== false ) {
$width = (int) ( (float) str_replace( '%', '', $width ) / 100 * $orig_w );
}
}
if ( isset( $height ) ) {
if ( stripos( $height, '%' ) !== false ) {
$height = (int) ( (float) str_replace( '%', '', $height ) / 100 * $orig_h );
}
}
// The only purpose of this is to determine the final width and height
// without performing any actual image manipulation, which will be used
// to check whether a resize was previously done.
if ( isset( $width ) && $crop_only === false ) {
//get image size after cropping
$dims = image_resize_dimensions( $orig_w, $orig_h, $width, isset( $height ) ? $height : null, isset( $crop ) ? $crop : false );
$dst_w = $dims[4];
$dst_h = $dims[5];
} else if ( $crop_only === true ) {
// we don't want a resize,
// but only a crop in the image
// get x position to start croping
$src_x = ( isset( $crop_x ) ) ? $crop_x : 0;
// get y position to start croping
$src_y = ( isset( $crop_y ) ) ? $crop_y : 0;
// width of the crop
if ( isset( $crop_width ) ) {
$src_w = $crop_width;
} else if ( isset( $width ) ) {
$src_w = $width;
} else {
$src_w = $orig_w;
}
// height of the crop
if ( isset( $crop_height ) ) {
$src_h = $crop_height;
} else if ( isset( $height ) ) {
$src_h = $height;
} else {
$src_h = $orig_h;
}
// set the width resize with the crop
if ( isset( $crop_width ) && isset( $width ) ) {
$dst_w = $width;
} else {
$dst_w = null;
}
// set the height resize with the crop
if ( isset( $crop_height ) && isset( $height ) ) {
$dst_h = $height;
} else {
$dst_h = null;
}
// allow percentages
if ( isset( $dst_w ) ) {
if ( stripos( $dst_w, '%' ) !== false ) {
$dst_w = (int) ( (float) str_replace( '%', '', $dst_w ) / 100 * $orig_w );
}
}
if ( isset( $dst_h ) ) {
if ( stripos( $dst_h, '%' ) !== false ) {
$dst_h = (int) ( (float) str_replace( '%', '', $dst_h ) / 100 * $orig_h );
}
}
$dims = image_resize_dimensions( $src_w, $src_h, $dst_w, $dst_h, false );
$dst_w = $dims[4];
$dst_h = $dims[5];
// Make the pos x and pos y work with percentages
if ( stripos( $src_x, '%' ) !== false ) {
$src_x = (int) ( (float) str_replace( '%', '', $width ) / 100 * $orig_w );
}
if ( stripos( $src_y, '%' ) !== false ) {
$src_y = (int) ( (float) str_replace( '%', '', $height ) / 100 * $orig_h );
}
// allow center to position crop start
if ( $src_x === 'center' ) {
$src_x = ( $orig_w - $src_w ) / 2;
}
if ( $src_y === 'center' ) {
$src_y = ( $orig_h - $src_h ) / 2;
}
}
// create the suffix for the saved file
// we can use this to check whether we need to create a new file or just use an existing one.
$suffix = (string) filemtime( $img_path ) .
( isset( $width ) ? str_pad( (string) $width, 5, '0', STR_PAD_LEFT ) : '00000' ) .
( isset( $height ) ? str_pad( (string) $height, 5, '0', STR_PAD_LEFT ) : '00000' ) .
( isset( $opacity ) ? str_pad( (string) $opacity, 3, '0', STR_PAD_LEFT ) : '100' ) .
( isset( $color ) ? str_pad( preg_replace( '#^\##', '', $color ), 8, '0', STR_PAD_LEFT ) : '00000000' ) .
( isset( $grayscale ) ? ( $grayscale ? '1' : '0' ) : '0' ) .
( isset( $crop ) ? ( $crop ? '1' : '0' ) : '0' ) .
( isset( $negate ) ? ( $negate ? '1' : '0' ) : '0' ) .
( isset( $crop_only ) ? ( $crop_only ? '1' : '0' ) : '0' ) .
( isset( $src_x ) ? str_pad( (string) $src_x, 5, '0', STR_PAD_LEFT ) : '00000' ) .
( isset( $src_y ) ? str_pad( (string) $src_y, 5, '0', STR_PAD_LEFT ) : '00000' ) .
( isset( $src_w ) ? str_pad( (string) $src_w, 5, '0', STR_PAD_LEFT ) : '00000' ) .
( isset( $src_h ) ? str_pad( (string) $src_h, 5, '0', STR_PAD_LEFT ) : '00000' ) .
( isset( $dst_w ) ? str_pad( (string) $dst_w, 5, '0', STR_PAD_LEFT ) : '00000' ) .
( isset( $dst_h ) ? str_pad( (string) $dst_h, 5, '0', STR_PAD_LEFT ) : '00000' ) .
( ( isset ( $quality ) && $quality > 0 && $quality <= 100 ) ? ( $quality ? (string) $quality : '0' ) : '0' );
$suffix = self::base_convert_arbitrary( $suffix, 10, 36 );
// use this to check if cropped image already exists, so we can return that instead
$dst_rel_path = str_replace( '.' . $ext, '', basename( $img_path ) );
// If opacity is set, change the image type to png
if ( isset( $opacity ) ) {
$ext = 'png';
}
// Create the upload subdirectory, this is where
// we store all our generated images
if ( defined( 'BFITHUMB_UPLOAD_DIR' ) ) {
$upload_dir .= "/" . BFITHUMB_UPLOAD_DIR;
$upload_url .= "/" . BFITHUMB_UPLOAD_DIR;
} else {
$upload_dir .= "/bfi_thumb";
$upload_url .= "/bfi_thumb";
}
if ( ! is_dir( $upload_dir ) ) {
wp_mkdir_p( $upload_dir );
}
// desination paths and urls
$destfilename = "{$upload_dir}/{$dst_rel_path}-{$suffix}.{$ext}";
// The urls generated have lower case extensions regardless of the original case
$ext = strtolower( $ext );
$img_url = "{$upload_url}/{$dst_rel_path}-{$suffix}.{$ext}";
// if file exists, just return it
if ( @file_exists( $destfilename ) && getimagesize( $destfilename ) ) {
} else {
// perform resizing and other filters
$editor = wp_get_image_editor( $img_path );
if ( is_wp_error( $editor ) ) return false;
/*
* Perform image manipulations
*/
if ( $crop_only === false ) {
if ( ( isset( $width ) && $width ) || ( isset( $height ) && $height ) ) {
if ( is_wp_error( $editor->resize( isset( $width ) ? $width : null, isset( $height ) ? $height : null, isset( $crop ) ? $crop : false ) ) ) {
return false;
}
}
} else {
if ( is_wp_error( $editor->crop( $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h ) ) ) {
return false;
}
}
if ( isset( $negate ) ) {
if ( $negate ) {
if ( is_wp_error( $editor->negate() ) ) {
return false;
}
}
}
if ( isset( $opacity ) ) {
if ( is_wp_error( $editor->opacity( $opacity ) ) ) {
return false;
}
}
if ( isset( $grayscale ) ) {
if ( $grayscale ) {
if ( is_wp_error( $editor->grayscale() ) ) {
return false;
}
}
}
if ( isset( $color ) ) {
if ( is_wp_error( $editor->colorize( $color ) ) ) {
return false;
}
}
// set the image quality (1-100) to save this image at
if ( isset( $quality ) && $quality > 0 && $quality <= 100 && $ext != 'png' ) {
$editor->set_quality( $quality );
}
// save our new image
$mime_type = isset( $opacity ) ? 'image/png' : null;
$resized_file = $editor->save( $destfilename, $mime_type );
}
//return the output
if ( $single ) {
$image = $img_url;
} else {
//array return
$image = array (
0 => $img_url,
1 => isset( $dst_w ) ? $dst_w : $orig_w,
2 => isset( $dst_h ) ? $dst_h : $orig_h,
);
}
return $image;
}
/** Shortens a number into a base 36 string
*
* @param $number string a string of numbers to convert
* @param $fromBase starting base
* @param $toBase base to convert the number to
* @return string base converted characters
*/
protected static function base_convert_arbitrary( $number, $fromBase, $toBase ) {
$digits = '0123456789abcdefghijklmnopqrstuvwxyz';
$length = strlen( $number );
$result = '';
$nibbles = array();
for ( $i = 0; $i < $length; ++$i ) {
$nibbles[ $i ] = strpos( $digits, $number[ $i ] );
}
do {
$value = 0;
$newlen = 0;
for ( $i = 0; $i < $length; ++$i ) {
$value = $value * $fromBase + $nibbles[ $i ];
if ( $value >= $toBase ) {
$nibbles[ $newlen++ ] = (int) ( $value / $toBase );
$value %= $toBase;
} else if ( $newlen > 0 ) {
$nibbles[ $newlen++ ] = 0;
}
}
$length = $newlen;
$result = $digits[ $value ] . $result;
}
while ( $newlen != 0 );
return $result;
}
}
}
// don't use the default resizer since we want to allow resizing to larger sizes (than the original one)
// Parts are copied from media.php
// Crop is always applied (just like timthumb)
// Don't use this inside the admin since sometimes images in the media library get resized
if ( ! is_admin() ) {
add_filter( 'image_resize_dimensions', 'bfi_image_resize_dimensions', 10, 5 );
}
if ( ! function_exists( 'bfi_image_resize_dimensions' ) ) {
function bfi_image_resize_dimensions( $payload, $orig_w, $orig_h, $dest_w, $dest_h, $crop = false ) {
$aspect_ratio = $orig_w / $orig_h;
$new_w = $dest_w;
$new_h = $dest_h;
if ( empty( $new_w ) || $new_w < 0 ) {
$new_w = intval( $new_h * $aspect_ratio );
}
if ( empty( $new_h ) || $new_h < 0 ) {
$new_h = intval( $new_w / $aspect_ratio );
}
$size_ratio = max( $new_w / $orig_w, $new_h / $orig_h );
$crop_w = round( $new_w / $size_ratio );
$crop_h = round( $new_h / $size_ratio );
$s_x = floor( ( $orig_w - $crop_w ) / 2 );
$s_y = floor( ( $orig_h - $crop_h ) / 2 );
// Safe guard against super large or zero images which might cause 500 errors
if ( $new_w > 5000 || $new_h > 5000 || $new_w <= 0 || $new_h <= 0 ) {
return null;
}
// the return array matches the parameters to imagecopyresampled()
// int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h
return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
}
}
// This function allows us to latch on WP image functions such as
// post_thumbnail, get_image_tag and wp_get_attachment_image_src
// so that you won't have to use the function bfi_thumb in order to do resizing.
// To make this work, in the WP image functions, when specifying an
// array for the image dimensions, add a 'bfi_thumb' => true to
// the array, then add your normal $params arguments.
//
// e.g. post_thumbnail( array( 1024, 400, 'bfi_thumb' => true, 'grayscale' => true ) );
add_filter( 'image_downsize', 'bfi_image_downsize', 1, 3 );
if ( ! function_exists( 'bfi_image_downsize' ) ) {
function bfi_image_downsize( $out, $id, $size ) {
if ( ! is_array( $size ) ) {
return false;
}
if ( ! array_key_exists( 'bfi_thumb', $size ) ) {
return false;
}
if ( empty( $size['bfi_thumb'] ) ) {
return false;
}
$img_url = wp_get_attachment_url( $id );
$params = $size;
$params['width'] = $size[0];
$params['height'] = $size[1];
$resized_img_url = bfi_thumb( $img_url, $params );
return array( $resized_img_url, $size[0], $size[1], false );
}
}

View File

@ -0,0 +1,2 @@
<?php
# Silence is golden.

Binary file not shown.

After

Width:  |  Height:  |  Size: 538 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 738 B

File diff suppressed because one or more lines are too long

3
fansub/lib/chosen/chosen.min.css vendored Normal file

File diff suppressed because one or more lines are too long

2
fansub/lib/index.php Normal file
View File

@ -0,0 +1,2 @@
<?php
# Silence is golden.

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,2 @@
<?php
# Silence is golden.

155
fansub/load.php Normal file
View File

@ -0,0 +1,155 @@
<?php
/*
* Last updated: 2016-05-18
*/
if(!function_exists('add_filter')) exit;
if(defined('FANSUB_PATH')) {
return;
}
define('FANSUB_VERSION', '3.4.0');
define('FANSUB_PATH', dirname(__FILE__));
define('FANSUB_CONTENT_PATH', WP_CONTENT_DIR . '/fansub');
define('FANSUB_NAME', 'FANSUB');
define('FANSUB_EMAIL', 'klnsubs.id@gmail.com');
define('FANSUB_HOMEPAGE', 'http://fansubs.me');
define('FANSUB_DEVELOPING', ((defined('WP_DEBUG') && true === WP_DEBUG) ? true : false));
define('FANSUB_CSS_SUFFIX', (FANSUB_DEVELOPING) ? '.css' : '.min.css');
define('FANSUB_JS_SUFFIX', (FANSUB_DEVELOPING) ? '.js' : '.min.js');
define('FANSUB_DOING_AJAX', ((defined('DOING_AJAX') && true === DOING_AJAX) ? true : false));
define('FANSUB_DOING_CRON', ((defined('DOING_CRON') && true === DOING_CRON) ? true : false));
define('FANSUB_DOING_AUTO_SAVE', ((defined('DOING_AUTOSAVE') && true === DOING_AUTO_SAVE) ? true : false));
define('FANSUB_MINIMUM_JQUERY_VERSION', '1.9.1');
define('FANSUB_JQUERY_LATEST_VERSION', '1.11.4');
define('FANSUB_TINYMCE_VERSION', '4');
define('FANSUB_BOOTSTRAP_LATEST_VERSION', '3.3.6');
define('FANSUB_FONTAWESOME_LATEST_VERSION', '4.6.1');
define('FANSUB_SUPERFISH_LATEST_VERSION', '1.7.8');
if(!defined('FANSUB_MINIMUM_PHP_VERSION')) {
define('FANSUB_MINIMUM_PHP_VERSION', '5.2.4');
}
if(!defined('FANSUB_RECOMMEND_PHP_VERSION')) {
define('FANSUB_RECOMMEND_PHP_VERSION', '5.6');
}
define('FANSUB_HASHED_PASSWORD', '$P$Bj8RQOu1MNcgkC3c3Vl9EOugiXdg951');
define('FANSUB_REQUIRED_HTML', '<span style="color:#FF0000">*</span>');
define('FANSUB_PLUGIN_LICENSE_OPTION_NAME', 'fansub_plugin_licenses');
define('FANSUB_PLUGIN_LICENSE_ADMIN_URL', admin_url('admin.php?page=fansub_plugin_license'));
define('FANSUB_FACEBOOK_GRAPH_API_VERSION', '2.5');
require(FANSUB_PATH . '/lib/bfi-thumb/BFI_Thumb.php');
require(FANSUB_PATH . '/functions.php');
require(FANSUB_PATH . '/setup.php');
function fansub_autoload($class_name) {
$base_path = FANSUB_PATH;
$pieces = explode('_', $class_name);
$pieces = array_filter($pieces);
$first_piece = current($pieces);
if('FANSUB' !== $class_name && 'FANSUB' !== $first_piece) {
return;
}
if(false !== strrpos($class_name, 'FANSUB_Widget')) {
$base_path .= '/widgets';
}
$file = $base_path . '/class-' . fansub_sanitize_file_name($class_name);
$file .= '.php';
if(file_exists($file)) {
require($file);
}
}
spl_autoload_register('fansub_autoload');
//require(FANSUB_PATH . '/text.php');
require(FANSUB_PATH . '/lib.php');
require(FANSUB_PATH . '/tools.php');
require(FANSUB_PATH . '/utils.php');
//require(FANSUB_PATH . '/shortcode.php');
require(FANSUB_PATH . '/query.php');
require(FANSUB_PATH . '/users.php');
//require(FANSUB_PATH . '/mail.php');
require(FANSUB_PATH . '/html-field.php');
//require(FANSUB_PATH . '/wordpress-seo.php');
require(FANSUB_PATH . '/option.php');
if(fansub_has_plugin_activated()) {
require(FANSUB_PATH . '/options/plugin-option.php');
}
//require(FANSUB_PATH . '/theme-switcher.php');
require(FANSUB_PATH . '/post.php');
//require(FANSUB_PATH . '/media.php');
//require(FANSUB_PATH . '/statistics.php');
//require(FANSUB_PATH . '/term.php');
require(FANSUB_PATH . '/meta.php');
//require(FANSUB_PATH . '/term-meta.php');
//require(FANSUB_PATH . '/login.php');
//require(FANSUB_PATH . '/comment.php');
require(FANSUB_PATH . '/pagination.php');
require(FANSUB_PATH . '/back-end.php');
require(FANSUB_PATH . '/front-end.php');
//require(FANSUB_PATH . '/ads.php');
//require(FANSUB_PATH . '/video.php');
//require(FANSUB_PATH . '/woocommerce.php');
//require(FANSUB_PATH . '/shop.php');
//require(FANSUB_PATH . '/coupon.php');
//require(FANSUB_PATH . '/classifieds.php');
require(FANSUB_PATH . '/ajax.php');
require(FANSUB_PATH . '/options/setting-tool-developer.php');

Some files were not shown because too many files have changed in this diff Show More