Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
Version 1.2.0 released
  • Loading branch information
DenisCherniatev committed Oct 30, 2017
2 parents 3f44c99 + 95fda91 commit 8151b0d
Show file tree
Hide file tree
Showing 14 changed files with 482 additions and 457 deletions.
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Kandinsky changelog
All notable changes to this project will be documented in this file.

## [Unreleased]

## [1.2.0] - 2017-10-30
### Added
- Version on dashboard and in console menus.

### Fixed
- Important security issues.

## [1.1.0] - 2017-10-17
### Added
- Ability to update theme right from admin panel.

### Fixed
- Invisible text in header.
- Other minor reported issues.

## [1.0.0] - 2017-09-27
### First official release!

[Unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.2.0...HEAD
[1.2.0]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.1.0...v1.2.0
[1.1.0]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.0.0...v1.1.0
12 changes: 12 additions & 0 deletions core/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ function knd_get_admin_menu_items( $place = '' ) {
'text' => esc_html__( 'Report of an error', 'knd' ),
'link' => esc_url( 'https://github.com/Teplitsa/kandinsky/issues/new' )
),
'theme-version' => array(
'class' => '',
'icon' => 'dashicons-tag',
'text' => sprintf( esc_html__( 'Version %s', 'knd' ), KND_VERSION),
'link' => KND_SOURCES_PAGE_URL
),
'update-theme' => array(
'class' => 'knd-update-theme',
'icon' => 'dashicons-controls-repeat',
Expand Down Expand Up @@ -176,6 +182,12 @@ function knd_get_admin_menu_items( $place = '' ) {
'text' => esc_html__( 'Email to the tech support', 'knd' ),
'link' => 'mailto:' . KND_SUPPORT_EMAIL
),
'theme-version' => array(
'class' => '',
'icon' => 'dashicons-tag',
'text' => sprintf( esc_html__( 'Version %s', 'knd' ), KND_VERSION),
'link' => KND_SOURCES_PAGE_URL
),
'update-theme' => array(
'class' => 'knd-update-theme',
'icon' => 'dashicons-controls-repeat',
Expand Down
105 changes: 48 additions & 57 deletions core/class-import.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function import_file( $url ) {
public function import_big_file( $url ) {
$tmp_dir = knd_get_temp_dir();

if ( ! is_dir( $tmp_dir ) && ! mkdir( $tmp_dir ) ) {
if ( ! Knd_Filesystem::get_instance()->is_dir( $tmp_dir ) && ! Knd_Filesystem::get_instance()->mkdir( $tmp_dir ) ) {
throw new Exception( sprintf( esc_html__( "Can't create a download temporary directory: %s", 'knd' ), $tmp_dir ) );
}

Expand Down Expand Up @@ -190,7 +190,7 @@ public function import_file_from_path( $path ) {
return false;

$attachment_id = false;
$file = file_get_contents( $path );
$file = Knd_Filesystem::get_instance()->get_contents( $path );

if ( $file ) {

Expand Down Expand Up @@ -273,11 +273,11 @@ public function convert2pdf( $attachment_id, $localpdf = '' ) {

if ( $localpdf ) {
$localpdf_file = preg_replace( '/\/$/', '', $localpdf ) . '/' . $new_file_base_name;
if ( file_exists( $localpdf_file ) ) {
copy( $localpdf_file, $new_file_no_prefix );
if ( Knd_Filesystem::get_instance()->exists( $localpdf_file ) ) {
Knd_Filesystem::get_instance()->copy( $localpdf_file, $new_file_no_prefix );
}
} else {
TST_Convert2PDF::get_instance()->doc2pdf( $original_file, $new_file );
// TST_Convert2PDF::get_instance()->doc2pdf( $original_file, $new_file );
}

if ( $localpdf && file_exists( $new_file_no_prefix ) ) {
Expand Down Expand Up @@ -305,7 +305,7 @@ public function convert2pdf( $attachment_id, $localpdf = '' ) {
}

unlink( $new_file_no_prefix );
} elseif ( file_exists( $new_file ) ) {
} elseif ( Knd_Filesystem::get_instance()->exists( $new_file ) ) {
$this->copy_to_localpdf( $new_file, $new_file_base_name );
unlink( $new_file );
}
Expand All @@ -321,8 +321,8 @@ public function copy_to_localpdf( $new_file, $new_file_base_name ) {
}

$localpdf_file = $pdf_dirname . '/' . $new_file_base_name;
if ( ! file_exists( $localpdf_file ) ) {
copy( $new_file, $localpdf_file );
if ( ! Knd_Filesystem::get_instance()->exists( $localpdf_file ) ) {
Knd_Filesystem::get_instance()->copy( $new_file, $localpdf_file );
}
}

Expand All @@ -340,13 +340,12 @@ public function remove_url_tag( $url, $content ) {
}

public function get_file_name( $url, $content ) {
$title = '';


$matches = array();
preg_match( '/<a[^>]*' . preg_quote( $url, '/' ) . '.*?>(.*?)<\/a>/i', $content, $matches );
$title = isset( $matches[1] ) ? $matches[1] : '';
$title = $this->clean_string( $title );

return $title;
}

Expand All @@ -362,7 +361,7 @@ public function clean_string( $s ) {

public function get_date_from_url( $url, $parse_rules ) {
$file_date = '';

foreach ( $parse_rules as $k => $v ) {
if ( preg_match( $v['regexp'], $url, $matches ) ) {
if ( isset( $matches[1] ) ) {
Expand All @@ -377,13 +376,13 @@ public function get_date_from_url( $url, $parse_rules ) {
break;
}
}

return $file_date;
}

public function get_exact_date_from_url( $url, $parse_rules ) {
$file_date = '';

foreach ( $parse_rules as $k => $v ) {
if ( preg_match( $v['regexp'], $url, $matches ) ) {
if ( isset( $matches[1] ) ) {
Expand All @@ -399,7 +398,7 @@ public function get_exact_date_from_url( $url, $parse_rules ) {
break;
}
}

return $file_date;
}

Expand All @@ -408,11 +407,11 @@ public function set_file_date( $file_id, $url, $tag_slug = '' ) {
if ( $tag_slug && isset( self::$date_from_url[$tag_slug] ) ) {
$date_parse_rules[$tag_slug] = self::$date_from_url[$tag_slug];
}

if ( ! count( $date_parse_rules ) ) {
$date_parse_rules = self::$date_from_url;
}

foreach ( $date_parse_rules as $tag_slug => $parse_rules ) {
$file_date = TST_Import::get_instance()->get_date_from_url( $url, $parse_rules );
if ( $file_date ) {
Expand All @@ -424,30 +423,30 @@ public function set_file_date( $file_id, $url, $tag_slug = '' ) {

function get_attachment_guid_by_url( $url ) {
$parsed_url = explode( parse_url( WP_CONTENT_URL, PHP_URL_PATH ), $url );

$this_host = str_ireplace( 'www.', '', parse_url( home_url(), PHP_URL_HOST ) );
$file_host = str_ireplace( 'www.', '', parse_url( $url, PHP_URL_HOST ) );

if ( ! isset( $parsed_url[1] ) || empty( $parsed_url[1] ) || ( $this_host != $file_host ) ) {
return;
}

return WP_CONTENT_URL . $parsed_url[1];
}

function get_attachment_id_by_url( $url ) {
$parsed_url = explode( parse_url( WP_CONTENT_URL, PHP_URL_PATH ), $url );

$this_host = str_ireplace( 'www.', '', parse_url( home_url(), PHP_URL_HOST ) );
$file_host = str_ireplace( 'www.', '', parse_url( $url, PHP_URL_HOST ) );

if ( ! isset( $parsed_url[1] ) || empty( $parsed_url[1] ) || ( $this_host != $file_host ) ) {
return;
}
global $wpdb;
$attachment = $wpdb->get_col(
$attachment = $wpdb->get_col(
$wpdb->prepare( "SELECT ID FROM {$wpdb->prefix}posts WHERE guid LIKE %s;", '%' . $parsed_url[1] ) );

return count( $attachment ) ? $attachment[0] : 0;
}

Expand All @@ -456,23 +455,23 @@ public function clean_content_xpath( $content, $section ) {
isset( $section['xpath']['title'] ) ) {
$section["clean_content_xpath"] = array();
}

if ( isset( $section['xpath']['title'] ) ) {
if ( ! is_array( $section['xpath']['title'] ) ) {
$section["clean_content_xpath"][] = $section['xpath']['title'];
}
}

if ( is_array( $section["clean_content_xpath"] ) ) {
$dom = new DOMDocument( '1.0', 'UTF-8' );

$dom->loadHTML(
'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . $content,
$dom->loadHTML(
'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . $content,
LIBXML_NOWARNING | LIBXML_NOERROR );

$nodes2delete = array();
$xpath = new DomXPath( $dom );

foreach ( $section["clean_content_xpath"] as $v ) {
if ( ! $v ) {
continue;
Expand All @@ -483,7 +482,7 @@ public function clean_content_xpath( $content, $section ) {
$nodes2delete[] = $node;
}
}

foreach ( $nodes2delete as $element ) {
try {
if ( $element->parentNode ) {
Expand All @@ -492,17 +491,17 @@ public function clean_content_xpath( $content, $section ) {
} catch ( Exception $ex ) {
}
}

$xpath = new DomXPath( $dom );
$body = $xpath->query( './/body' );
$body = $body ? $body->item( 0 ) : NULL;
$content = $body ? $this->get_inner_html( $body ) : '';

unset( $body );
unset( $xpath );
unset( $nodes2delete );
}

return $content;
}

Expand All @@ -518,20 +517,20 @@ public function clean_content_regexp( $content, $section ) {
$content = preg_replace( $regexp, "", $content, $limit );
}
}

return $content;
}

public function get_inner_html( DOMNode $element ) {
$innerHTML = "";
$children = $element->childNodes;

if ( $children ) {
foreach ( $children as $child ) {
$innerHTML .= $element->ownerDocument->saveHTML( $child );
}
}

return $innerHTML;
}

Expand All @@ -544,25 +543,25 @@ function clean_content( $content, $section ) {
$content = $this->remove_script( $content );
$content = $this->clean_content_regexp( $content, $section );
$content = $this->clean_content_xpath( $content, $section );

return $content;
}

function urls_rel2abs( $content, $base_url, $dront_site_url ) {
$content = preg_replace(
'/(src|href)\s*=\s*(["\'])\s*(\/(?!\/)[^\"\' ]+)/',
'\1=\2' . $dront_site_url . '\3',
$content = preg_replace(
'/(src|href)\s*=\s*(["\'])\s*(\/(?!\/)[^\"\' ]+)/',
'\1=\2' . $dront_site_url . '\3',
$content );
$content = preg_replace(
'/(src|href)\s*=\s*(["\'])\s*((?!https?:\/\/)[^\"\' ]+)/',
'\1=\2' . $base_url . '/\3',
$content = preg_replace(
'/(src|href)\s*=\s*(["\'])\s*((?!https?:\/\/)[^\"\' ]+)/',
'\1=\2' . $base_url . '/\3',
$content );
return $content;
}

function get_headers_from_curl_response( $header_text ) {
$headers = array();

foreach ( explode( "\r\n", $header_text ) as $i => $line ) {
if ( $i === 0 ) {
$headers['STATUS'] = $line;
Expand All @@ -575,7 +574,7 @@ function get_headers_from_curl_response( $header_text ) {
}
}
}

return $headers;
}

Expand All @@ -586,19 +585,11 @@ function remove_script( $html ) {

public function maybe_import( $external_file_url ) {
$exist_attachment = $this->get_attachment_by_old_url( $external_file_url );
$attachment_id = 0;


if ( $exist_attachment ) {
$file_id = $exist_attachment->ID;
$file_url = wp_get_attachment_url( $file_id );
$attachment_id = $exist_attachment->ID;
} else {
$attachment_id = $this->import_big_file( $external_file_url );

if ( $attachment_id ) {
$file_id = $attachment_id;
$file_url = wp_get_attachment_url( $attachment_id );
}
}
unset( $exist_attachment );

Expand All @@ -611,4 +602,4 @@ public function maybe_import_local_file( $filename ) {
$filename );
return $thumbnail_id;
}
} //class TST_Import
} //class TST_Import
Loading

0 comments on commit 8151b0d

Please sign in to comment.