feat(05-domain-seoadditional-cron-releases): Domain layer kompletny — SeoAdditional + Cron + Releases
Phase 5 complete: - Domain\SeoAdditional\SeoAdditionalRepository (elementDelete, elementSave, elementDetails) - Domain\Cron\CronRepository (3 pub + 12 private helper methods) - Domain\Releases\ReleasesRepository (9 metod: wersje, licencje, discover) - Domain\Releases\UpdateRepository (auto-update, konstruktor($db, $settings)) - 4 legacy factory wrappers zaktualizowane do wrapper delegation Domain layer: 13/13 repozytoriów kompletnych. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
495
autoload/Domain/Cron/CronRepository.php
Normal file
495
autoload/Domain/Cron/CronRepository.php
Normal file
@@ -0,0 +1,495 @@
|
||||
<?php
|
||||
namespace Domain\Cron;
|
||||
|
||||
class CronRepository
|
||||
{
|
||||
private $db;
|
||||
|
||||
public function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
public function automaticUpdateSites()
|
||||
{
|
||||
$results = $this->db->query( "SELECT id, url FROM projects WHERE automatic_update = 1 AND DATE_ADD( last_update, INTERVAL 1 WEEK ) <= '" . date( 'Y-m-d H:i:s' ) . "'" )->fetchAll();
|
||||
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$this->db->delete( 'project_links_internal', [ 'AND' => [ 'project_id' => $row['id'], 'parent_id[!]' => null ] ] );
|
||||
$this->db->delete( 'project_links_external', [ 'project_id' => $row['id'] ] );
|
||||
$this->db->update( 'project_links_internal', [ 'visited' => 0 ], [ 'project_id' => $row['id'] ] );
|
||||
|
||||
$this->db->update( 'projects', [ 'last_update' => date( 'Y-m-d H:i:s' ) ], [ 'id' => $row['id'] ] );
|
||||
|
||||
return [ 'status' => 'ok', 'msg' => 'Ponawiam sprawdzanie strony <a href="' . $row['url'] . '" target="_blank">' . $row['url'] . '</a>' ];
|
||||
}
|
||||
return [ 'status' => 'empty' ];
|
||||
}
|
||||
|
||||
public function getSiteMainLinks()
|
||||
{
|
||||
$results = $this->db->query( 'SELECT id, url FROM projects WHERE id NOT IN ( SELECT project_id FROM project_links_internal GROUP BY project_id ) AND enabled = 1 LIMIT 1' )->fetchAll();
|
||||
if ( is_array( $results ) and !empty ( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt( $ch, CURLOPT_URL, $row['url'] );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
|
||||
curl_setopt( $ch, CURLOPT_VERBOSE, 1 );
|
||||
curl_setopt( $ch, CURLOPT_TIMEOUT, 60 );
|
||||
curl_setopt( $ch, CURLOPT_HEADER, true );
|
||||
curl_setopt( $ch, CURLOPT_CAINFO, 'cacert.pem' );
|
||||
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
|
||||
curl_setopt( $ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.103 Safari/537.36' );
|
||||
$response = curl_exec( $ch );
|
||||
curl_close ( $ch );
|
||||
|
||||
if ( !curl_errno( $ch ) )
|
||||
{
|
||||
$this->db->insert( 'project_links_internal', [
|
||||
'project_id' => $row['id'],
|
||||
'url' => $row['url'],
|
||||
'parent_id' => null
|
||||
] );
|
||||
|
||||
$doc = new \DOMDocument;
|
||||
$doc->loadHTML( $response );
|
||||
foreach ( $doc->getElementsByTagName( 'a' ) as $link )
|
||||
{
|
||||
$url = $link->getAttribute( 'href' );
|
||||
|
||||
if ( \S::is_url_internal( $row['url'], $url ) )
|
||||
{
|
||||
if ( strpos( $url, '#' ) !== false )
|
||||
$url = rtrim( substr( $url, 0, strpos( $url, '#' ) ), '?,#' );
|
||||
|
||||
$url = \S::modify_internal_link( $row['url'], $url );
|
||||
|
||||
if ( !filter_var( $url, FILTER_VALIDATE_URL ) === false and !$this->db->count( 'project_links_internal', [ 'AND' => [ 'project_id' => $row['id'], 'url' => $url ] ] ) )
|
||||
{
|
||||
$this->db->insert( 'project_links_internal', [
|
||||
'project_id' => $row['id'],
|
||||
'url' => $url
|
||||
] );
|
||||
}
|
||||
}
|
||||
}
|
||||
return [ 'status' => 'ok', 'msg' => 'Pobieram linki dla strony <a href="' . $row['url'] . '" target="_blank">' . $row['url'] . '</a>' ];
|
||||
}
|
||||
else
|
||||
return [ 'status' => 'ok', 'msg' => 'Błąd podczas pobierania strony <a href="' . $row['url'] . '" target="_blank">' . $row['url'] . '</a>' ];
|
||||
}
|
||||
return [ 'status' => 'empty' ];
|
||||
}
|
||||
|
||||
public function getSiteOtherLinks()
|
||||
{
|
||||
$results = $this->db->query( 'SELECT '
|
||||
. 'pli.id, project_id, pli.url, p.url AS project_url '
|
||||
. 'FROM '
|
||||
. 'project_links_internal AS pli '
|
||||
. 'INNER JOIN projects AS p ON p.id = pli.project_id '
|
||||
. 'WHERE '
|
||||
. 'visited = 0 AND enabled = 1 '
|
||||
. 'LIMIT 1' )->fetchAll();
|
||||
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$url = parse_url( $row['url'] );
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
|
||||
curl_setopt( $ch, CURLOPT_VERBOSE, 1 );
|
||||
curl_setopt( $ch, CURLOPT_TIMEOUT, 60 );
|
||||
curl_setopt( $ch, CURLOPT_COOKIEFILE, 'temp/cookie.txt' );
|
||||
curl_setopt( $ch, CURLOPT_COOKIEJAR, 'temp/cookie.txt' );
|
||||
curl_setopt( $ch, CURLOPT_CAINFO, 'cacert.pem' );
|
||||
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
|
||||
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
|
||||
curl_setopt( $ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.103 Safari/537.36' );
|
||||
|
||||
curl_setopt( $ch, CURLOPT_URL, 'http://' . $url['host'] );
|
||||
$response = curl_exec( $ch );
|
||||
|
||||
curl_setopt( $ch, CURLOPT_URL, $row['url'] );
|
||||
$response = curl_exec( $ch );
|
||||
$content_type = curl_getinfo( $ch, CURLINFO_CONTENT_TYPE );
|
||||
$code = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
|
||||
curl_close ( $ch );
|
||||
|
||||
if ( !curl_errno( $ch ) and ( $code == 200 or $code == 301 ) and strpos( $content_type, 'text/html' ) !== false )
|
||||
{
|
||||
$this->getSiteMetaTitle( $row['id'], $response );
|
||||
$this->getSiteMetaKeywords( $row['id'], $response );
|
||||
$this->getSiteMetaDescription( $row['id'], $response );
|
||||
$this->getSiteMetaRobots( $row['id'], $response );
|
||||
$this->getSiteMetaGooglebot( $row['id'], $response );
|
||||
$this->getSiteCodeLenght( $row['id'], $response );
|
||||
$this->getSiteTextLenght( $row['id'], $response );
|
||||
$this->getSiteCanonical( $row['id'], $response );
|
||||
$this->getTableExists( $row['id'], $response );
|
||||
$this->getIframeExists( $row['id'], $response );
|
||||
$this->getH1Exists( $row['id'], $response );
|
||||
$this->getImagesWithoutAlt( $row['id'], $response );
|
||||
|
||||
/* pobranie linków ze strony */
|
||||
$doc = new \DOMDocument;
|
||||
$doc->loadHTML( $response );
|
||||
|
||||
foreach ( $doc->getElementsByTagName( 'a' ) as $link )
|
||||
{
|
||||
$url = $link->getAttribute( 'href' );
|
||||
|
||||
/* linki wewnętrzne na danej postronie */
|
||||
if ( \S::is_url_internal( $row['project_url'], $url ) )
|
||||
{
|
||||
if ( strpos( $url, '#' ) !== false )
|
||||
$url = rtrim( substr( $url, 0, strpos( $url, '#' ) ), '?,#' );
|
||||
|
||||
$url = \S::modify_internal_link( $row['project_url'], $url, $row['url'] );
|
||||
$info = pathinfo( $url );
|
||||
|
||||
if ( !filter_var( $url, FILTER_VALIDATE_URL ) === false and !in_array( strtolower( $info['extension'] ), \S::not_html_format() ) and !$this->db->count( 'project_links_internal', [
|
||||
'AND' => [
|
||||
'project_id' => $row['project_id'],
|
||||
'url' => $url
|
||||
]
|
||||
] ) )
|
||||
{
|
||||
$this->db->insert( 'project_links_internal', [
|
||||
'project_id' => $row['project_id'],
|
||||
'url' => $url,
|
||||
'visited' => 0,
|
||||
'parent_id' => $row['id'],
|
||||
'response' => $response
|
||||
] );
|
||||
}
|
||||
}
|
||||
/* linki zewnętrzne na danej podstronie */
|
||||
else
|
||||
{
|
||||
$link->getAttribute( 'rel' ) == 'nofollow' ? $nofollow = 1 : $nofollow = 0;
|
||||
|
||||
$this->db->insert( 'project_links_external', [
|
||||
'project_id' => $row['project_id'],
|
||||
'link_id' => $row['id'],
|
||||
'url' => $link->getAttribute( 'href' ),
|
||||
'nofollow' => $nofollow,
|
||||
'title' => $link->getAttribute( 'title' )
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->update( 'project_links_internal', [
|
||||
'visited' => 1,
|
||||
'content_type' => $content_type,
|
||||
'response_code' => $code,
|
||||
'response' => $response
|
||||
], [
|
||||
'id' => $row['id']
|
||||
] );
|
||||
|
||||
return [ 'status' => 'ok', 'msg' => 'Pobieram informacje dla strony <a href="' . $row['url'] . '" target="_blank">' . $row['url'] . '</a>' ];
|
||||
}
|
||||
else if ( $code == 404 or strpos( $content_type, 'text/html' ) === false )
|
||||
{
|
||||
$this->db->update( 'project_links_internal', [
|
||||
'visited' => 1,
|
||||
'deleted' => 1,
|
||||
'content_type' => $content_type,
|
||||
'response_code' => $code
|
||||
], [
|
||||
'id' => $row['id']
|
||||
] );
|
||||
|
||||
return [ 'status' => 'ok', 'msg' => 'Pobieram informacje dla strony <a href="' . $row['url'] . '" target="_blank">' . $row['url'] . '</a>' ];
|
||||
}
|
||||
else if ( $code !== 200 and strpos( $content_type, 'text/html' ) !== false )
|
||||
{
|
||||
$this->db->update( 'project_links_internal', [
|
||||
'visited' => 1,
|
||||
'content_type' => $content_type,
|
||||
'response_code' => $code,
|
||||
'response' => $response
|
||||
], [
|
||||
'id' => $row['id']
|
||||
] );
|
||||
|
||||
return [ 'status' => 'ok', 'msg' => 'Pobieram informacje dla strony <a href="' . $row['url'] . '" target="_blank">' . $row['url'] . '</a>' ];
|
||||
}
|
||||
else
|
||||
return [ 'status' => 'ok', 'msg' => 'Błąd podczas pobierania strony <a href="' . $row['url'] . '" target="_blank">' . $row['url'] . '</a>' ];
|
||||
}
|
||||
return [ 'status' => 'empty' ];
|
||||
}
|
||||
|
||||
private function getImagesWithoutAlt( $urlId, $response )
|
||||
{
|
||||
$doc = new \DOMDocument;
|
||||
$doc->loadHTML( $response );
|
||||
$images = $doc->getElementsByTagName("img");
|
||||
|
||||
$have_images_without_alt = 0;
|
||||
foreach ( $images as $img )
|
||||
{
|
||||
if ( !$img->getAttribute( 'alt' ) )
|
||||
$have_images_without_alt = 1;
|
||||
}
|
||||
|
||||
$this->db->update( 'project_links_internal', [ 'have_images_without_alt' => $have_images_without_alt ], [ 'id' => $urlId ] );
|
||||
}
|
||||
|
||||
private function getTableExists( $urlId, $response )
|
||||
{
|
||||
$doc = new \DOMDocument;
|
||||
$doc->loadHTML( $response );
|
||||
$count = $doc->getElementsByTagName("table");
|
||||
|
||||
$this->db->update( 'project_links_internal', [ 'have_table' => $count->length ? 1 : 0 ], [ 'id' => $urlId ] );
|
||||
}
|
||||
|
||||
private function getIframeExists( $urlId, $response )
|
||||
{
|
||||
$doc = new \DOMDocument;
|
||||
$doc->loadHTML( $response );
|
||||
$count = $doc->getElementsByTagName("iframe");
|
||||
|
||||
$this->db->update( 'project_links_internal', [ 'have_iframe' => $count->length ? 1 : 0 ], [ 'id' => $urlId ] );
|
||||
}
|
||||
|
||||
private function getH1Exists( $urlId, $response )
|
||||
{
|
||||
$doc = new \DOMDocument;
|
||||
$doc->loadHTML( $response );
|
||||
$count = $doc->getElementsByTagName("h1");
|
||||
$this->db->update( 'project_links_internal', [ 'have_h1' => $count->length ? 1 : 0 ], [ 'id' => $urlId ] );
|
||||
}
|
||||
|
||||
private function getSiteMetaTitle( $urlId, $response )
|
||||
{
|
||||
$title = '';
|
||||
|
||||
preg_match('/<title>([^>]*)<\/title>/si', $response, $match );
|
||||
|
||||
if ( isset( $match ) && is_array( $match ) && count( $match ) > 0 )
|
||||
$title = (string)strip_tags( $match[1] );
|
||||
|
||||
if ( !$title )
|
||||
{
|
||||
preg_match_all('/<[\s]*meta[\s]*name="og:?' . '([^>"]*)"?[\s]*' . 'content="?([^>"]*)"?[\s]*[\/]?[\s]*>/si', $response, $match);
|
||||
|
||||
if ( isset ( $match ) && is_array( $match ) && count( $match ) == 3 )
|
||||
{
|
||||
$originals = $match[0];
|
||||
$names = $match[1];
|
||||
$values = $match[2];
|
||||
|
||||
if ( count( $originals ) == count( $names ) && count( $names ) == count( $values ) )
|
||||
{
|
||||
$metaTags = array();
|
||||
for ( $i = 0, $limiti = count( $names ); $i < $limiti; $i++ )
|
||||
{
|
||||
$metaTags[ $names[$i] ] = array(
|
||||
'html' => htmlentities( $originals[$i] ),
|
||||
'value' => $values[$i]
|
||||
);
|
||||
}
|
||||
}
|
||||
$title = (string)$metaTags['title']['value'];
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->update( 'project_links_internal', [ 'title' => $title ], [ 'id' => $urlId ] );
|
||||
}
|
||||
|
||||
private function getSiteCanonical( $urlId, $response )
|
||||
{
|
||||
$doc = new \DOMDocument;
|
||||
$doc->loadHTML( $response );
|
||||
foreach ( $doc->getElementsByTagName( 'link' ) as $link )
|
||||
{
|
||||
$rel = $link->getAttribute( 'rel' );
|
||||
|
||||
if ( $rel == 'canonical' )
|
||||
{
|
||||
$canonical = $link->getAttribute( 'href' );
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->update( 'project_links_internal', [ 'canonical' => $canonical ], [ 'id' => $urlId ] );
|
||||
}
|
||||
|
||||
private function getSiteMetaKeywords( $urlId, $response )
|
||||
{
|
||||
$meta_keywords = '';
|
||||
|
||||
preg_match_all( '/<[\s]*meta[\s]*name="?' . '([^>"]*)"?[\s]*' . 'content="?([^>"]*)"?[\s]*[\/]?[\s]*>/si', $response, $match );
|
||||
|
||||
if ( isset ( $match ) && is_array( $match ) && count( $match ) == 3 )
|
||||
{
|
||||
$originals = $match[0];
|
||||
$names = $match[1];
|
||||
$values = $match[2];
|
||||
|
||||
if ( count( $originals ) == count( $names ) && count( $names ) == count( $values ) )
|
||||
{
|
||||
$metaTags = array();
|
||||
for ( $i = 0, $limiti = count( $names ); $i < $limiti; $i++ )
|
||||
{
|
||||
$metaTags[ $names[$i] ] = array(
|
||||
'html' => htmlentities( $originals[$i] ),
|
||||
'value' => $values[$i]
|
||||
);
|
||||
}
|
||||
}
|
||||
$meta_keywords = (string)$metaTags['keywords']['value'];
|
||||
}
|
||||
|
||||
if ( !$meta_keywords )
|
||||
{
|
||||
preg_match_all( '/<[\s]*meta[\s]*property="og:?' . '([^>"]*)"?[\s]*' . 'content="?([^>"]*)"?[\s]*[\/]?[\s]*>/si', $response, $match );
|
||||
|
||||
if ( isset ( $match ) && is_array( $match ) && count( $match ) == 3 )
|
||||
{
|
||||
$originals = $match[0];
|
||||
$names = $match[1];
|
||||
$values = $match[2];
|
||||
|
||||
if ( count( $originals ) == count( $names ) && count( $names ) == count( $values ) )
|
||||
{
|
||||
$metaTags = array();
|
||||
for ( $i = 0, $limiti = count( $names ); $i < $limiti; $i++ )
|
||||
{
|
||||
$metaTags[ $names[$i] ] = array(
|
||||
'html' => htmlentities( $originals[$i] ),
|
||||
'value' => $values[$i]
|
||||
);
|
||||
}
|
||||
}
|
||||
$meta_keywords = (string)$metaTags['keywords']['value'];
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->update( 'project_links_internal', [ 'meta_keywords' => $meta_keywords ], [ 'id' => $urlId ] );
|
||||
}
|
||||
|
||||
private function getSiteMetaDescription( $urlId, $response )
|
||||
{
|
||||
$meta_description = '';
|
||||
|
||||
preg_match_all('/<[\s]*meta[\s]*name="?' . '([^>"]*)"?[\s]*' . 'content="?([^>"]*)"?[\s]*[\/]?[\s]*>/si', $response, $match);
|
||||
|
||||
if ( isset ( $match ) && is_array( $match ) && count( $match ) == 3 )
|
||||
{
|
||||
$originals = $match[0];
|
||||
$names = $match[1];
|
||||
$values = $match[2];
|
||||
|
||||
if ( count( $originals ) == count( $names ) && count( $names ) == count( $values ) )
|
||||
{
|
||||
$metaTags = array();
|
||||
for ( $i = 0, $limiti = count( $names ); $i < $limiti; $i++ )
|
||||
{
|
||||
$metaTags[ $names[$i] ] = array(
|
||||
'html' => htmlentities( $originals[$i] ),
|
||||
'value' => $values[$i]
|
||||
);
|
||||
}
|
||||
}
|
||||
$meta_description = (string)$metaTags['description']['value'];
|
||||
}
|
||||
|
||||
if ( !$meta_description )
|
||||
{
|
||||
preg_match_all( '/<[\s]*meta[\s]*property="og:?' . '([^>"]*)"?[\s]*' . 'content="?([^>"]*)"?[\s]*[\/]?[\s]*>/si', $response, $match );
|
||||
|
||||
if ( isset ( $match ) && is_array( $match ) && count( $match ) == 3 )
|
||||
{
|
||||
$originals = $match[0];
|
||||
$names = $match[1];
|
||||
$values = $match[2];
|
||||
|
||||
if ( count( $originals ) == count( $names ) && count( $names ) == count( $values ) )
|
||||
{
|
||||
$metaTags = array();
|
||||
for ( $i = 0, $limiti = count( $names ); $i < $limiti; $i++ )
|
||||
{
|
||||
$metaTags[ $names[$i] ] = array(
|
||||
'html' => htmlentities( $originals[$i] ),
|
||||
'value' => $values[$i]
|
||||
);
|
||||
}
|
||||
}
|
||||
$meta_description = (string)$metaTags['description']['value'];
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->update( 'project_links_internal', [ 'meta_description' => $meta_description ], [ 'id' => $urlId ] );
|
||||
}
|
||||
|
||||
private function getSiteMetaRobots( $urlId, $response )
|
||||
{
|
||||
$meta_robots = '';
|
||||
|
||||
preg_match_all('/<[\s]*meta[\s]*name="?' . '([^>"]*)"?[\s]*' . 'content="?([^>"]*)"?[\s]*[\/]?[\s]*>/si', $response, $match);
|
||||
|
||||
if ( isset ( $match ) && is_array( $match ) && count( $match ) == 3 )
|
||||
{
|
||||
$originals = $match[0];
|
||||
$names = $match[1];
|
||||
$values = $match[2];
|
||||
|
||||
if ( count( $originals ) == count( $names ) && count( $names ) == count( $values ) )
|
||||
{
|
||||
$metaTags = array();
|
||||
for ( $i = 0, $limiti = count( $names ); $i < $limiti; $i++ )
|
||||
{
|
||||
$metaTags[ $names[$i] ] = array(
|
||||
'html' => htmlentities( $originals[$i] ),
|
||||
'value' => $values[$i]
|
||||
);
|
||||
}
|
||||
}
|
||||
$meta_robots = (string)$metaTags['robots']['value'];
|
||||
}
|
||||
|
||||
$this->db->update( 'project_links_internal', [ 'meta_robots' => $meta_robots ], [ 'id' => $urlId ] );
|
||||
}
|
||||
|
||||
private function getSiteMetaGooglebot( $urlId, $response )
|
||||
{
|
||||
$meta_googlebot = '';
|
||||
|
||||
preg_match_all('/<[\s]*meta[\s]*name="?' . '([^>"]*)"?[\s]*' . 'content="?([^>"]*)"?[\s]*[\/]?[\s]*>/si', $response, $match);
|
||||
|
||||
if ( isset ( $match ) && is_array( $match ) && count( $match ) == 3 )
|
||||
{
|
||||
$originals = $match[0];
|
||||
$names = $match[1];
|
||||
$values = $match[2];
|
||||
|
||||
if ( count( $originals ) == count( $names ) && count( $names ) == count( $values ) )
|
||||
{
|
||||
$metaTags = array();
|
||||
for ( $i = 0, $limiti = count( $names ); $i < $limiti; $i++ )
|
||||
{
|
||||
$metaTags[ $names[$i] ] = array(
|
||||
'html' => htmlentities( $originals[$i] ),
|
||||
'value' => $values[$i]
|
||||
);
|
||||
}
|
||||
}
|
||||
$meta_googlebot = (string)$metaTags['googlebot']['value'];
|
||||
}
|
||||
|
||||
$this->db->update( 'project_links_internal', [ 'meta_googlebot' => $meta_googlebot ], [ 'id' => $urlId ] );
|
||||
}
|
||||
|
||||
private function getSiteCodeLenght( $urlId, $response )
|
||||
{
|
||||
$this->db->update( 'project_links_internal', [ 'code_lenght' => strlen( $response ) ], [ 'id' => $urlId ] );
|
||||
}
|
||||
|
||||
private function getSiteTextLenght( $urlId, $response )
|
||||
{
|
||||
$this->db->update( 'project_links_internal', [ 'text_lenght' => strlen( \S::strip_html_tags( $response ) ) ], [ 'id' => $urlId ] );
|
||||
}
|
||||
}
|
||||
101
autoload/Domain/Releases/ReleasesRepository.php
Normal file
101
autoload/Domain/Releases/ReleasesRepository.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
namespace Domain\Releases;
|
||||
|
||||
class ReleasesRepository
|
||||
{
|
||||
private $db;
|
||||
|
||||
public function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
public function getVersions(): array
|
||||
{
|
||||
$rows = $this->db->select('pp_update_versions', '*', ['ORDER' => ['version' => 'DESC']]);
|
||||
if (!$rows) return [];
|
||||
foreach ($rows as &$row)
|
||||
$row['zip_exists'] = file_exists('../updates/' . $this->zipDir($row['version']) . '/ver_' . $row['version'] . '.zip');
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public function promote(string $version): void
|
||||
{
|
||||
$this->db->update('pp_update_versions',
|
||||
['channel' => 'stable', 'promoted_at' => date('Y-m-d H:i:s')],
|
||||
['version' => $version]
|
||||
);
|
||||
}
|
||||
|
||||
public function demote(string $version): void
|
||||
{
|
||||
$this->db->update('pp_update_versions',
|
||||
['channel' => 'beta', 'promoted_at' => null],
|
||||
['version' => $version]
|
||||
);
|
||||
}
|
||||
|
||||
public function discoverVersions(): int
|
||||
{
|
||||
$known = array_flip($this->db->select('pp_update_versions', 'version', []) ?: []);
|
||||
$zips = glob('../updates/*/ver_*.zip') ?: [];
|
||||
$added = 0;
|
||||
foreach ($zips as $path) {
|
||||
preg_match('/ver_([0-9.]+)\.zip$/', $path, $m);
|
||||
if (!$m) continue;
|
||||
$ver = $m[1];
|
||||
if (isset($known[$ver])) continue;
|
||||
$this->db->insert('pp_update_versions', [
|
||||
'version' => $ver,
|
||||
'channel' => 'beta',
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
$known[$ver] = true;
|
||||
$added++;
|
||||
}
|
||||
return $added;
|
||||
}
|
||||
|
||||
public function getLicenses(): array
|
||||
{
|
||||
return $this->db->select('pp_update_licenses', '*', ['ORDER' => ['domain' => 'ASC']]) ?: [];
|
||||
}
|
||||
|
||||
public function getLicense(int $id): array
|
||||
{
|
||||
return $this->db->get('pp_update_licenses', '*', ['id' => $id]) ?: [];
|
||||
}
|
||||
|
||||
public function saveLicense(array $data): void
|
||||
{
|
||||
$row = [
|
||||
'key' => trim($data['key'] ?? ''),
|
||||
'domain' => trim($data['domain'] ?? ''),
|
||||
'valid_to_date' => $data['valid_to_date'] ?: null,
|
||||
'valid_to_version' => $data['valid_to_version'] ?: null,
|
||||
'beta' => (int)(bool)($data['beta'] ?? 0),
|
||||
'note' => trim($data['note'] ?? ''),
|
||||
];
|
||||
if (!empty($data['id']))
|
||||
$this->db->update('pp_update_licenses', $row, ['id' => (int)$data['id']]);
|
||||
else
|
||||
$this->db->insert('pp_update_licenses', $row);
|
||||
}
|
||||
|
||||
public function deleteLicense(int $id): void
|
||||
{
|
||||
$this->db->delete('pp_update_licenses', ['id' => $id]);
|
||||
}
|
||||
|
||||
public function toggleBeta(int $id): void
|
||||
{
|
||||
$license = $this->db->get('pp_update_licenses', ['id', 'beta'], ['id' => $id]);
|
||||
if ($license)
|
||||
$this->db->update('pp_update_licenses', ['beta' => $license['beta'] ? 0 : 1], ['id' => $id]);
|
||||
}
|
||||
|
||||
private function zipDir(string $version): string
|
||||
{
|
||||
return substr($version, 0, strlen($version) - (strlen($version) == 5 ? 2 : 1)) . '0';
|
||||
}
|
||||
}
|
||||
163
autoload/Domain/Releases/UpdateRepository.php
Normal file
163
autoload/Domain/Releases/UpdateRepository.php
Normal file
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
namespace Domain\Releases;
|
||||
|
||||
class UpdateRepository
|
||||
{
|
||||
private $db;
|
||||
private $settings;
|
||||
|
||||
public function __construct($db, $settings)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
public function update()
|
||||
{
|
||||
\S::delete_session( 'new-version' );
|
||||
|
||||
$versions = file_get_contents( 'https://www.cmspro.project-dc.pl/updates/versions.php?key=' . urlencode( $this->settings['update_key'] ) );
|
||||
$versions = explode( PHP_EOL, $versions );
|
||||
|
||||
foreach ( $versions as $ver )
|
||||
{
|
||||
$ver = trim( $ver );
|
||||
if ( (float)$ver > (float)\S::get_version() )
|
||||
{
|
||||
if ( strlen( $ver ) == 5 )
|
||||
$dir = substr( $ver, 0, strlen( $ver ) - 2 ) . 0;
|
||||
else
|
||||
$dir = substr( $ver, 0, strlen( $ver ) - 1 ) . 0;
|
||||
|
||||
$baseUrl = 'https://www.cmspro.project-dc.pl/updates/' . $dir;
|
||||
|
||||
/* pobranie paczki ZIP */
|
||||
$file = file_get_contents( $baseUrl . '/ver_' . $ver . '.zip' );
|
||||
|
||||
$dlHandler = fopen( 'update.zip' , 'w' );
|
||||
if ( !fwrite( $dlHandler, $file ) )
|
||||
return false;
|
||||
fclose( $dlHandler );
|
||||
|
||||
if ( !file_exists( 'update.zip' ) )
|
||||
return false;
|
||||
|
||||
/* pobranie manifestu JSON (nowy system) lub fallback na legacy _sql.txt / _files.txt */
|
||||
$manifest = null;
|
||||
$manifestJson = @file_get_contents( $baseUrl . '/ver_' . $ver . '_manifest.json' );
|
||||
if ( $manifestJson )
|
||||
{
|
||||
if ( substr( $manifestJson, 0, 3 ) === "\xEF\xBB\xBF" )
|
||||
$manifestJson = substr( $manifestJson, 3 );
|
||||
$manifest = @json_decode( $manifestJson, true );
|
||||
}
|
||||
|
||||
if ( is_array( $manifest ) )
|
||||
{
|
||||
/* weryfikacja checksum SHA256 */
|
||||
if ( !empty( $manifest['checksum_zip'] ) )
|
||||
{
|
||||
$expectedHash = str_replace( 'sha256:', '', $manifest['checksum_zip'] );
|
||||
$actualHash = hash_file( 'sha256', 'update.zip' );
|
||||
if ( $expectedHash !== $actualHash )
|
||||
{
|
||||
unlink( 'update.zip' );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* aktualizacja bazy danych z manifestu */
|
||||
if ( !empty( $manifest['sql'] ) && is_array( $manifest['sql'] ) )
|
||||
{
|
||||
foreach ( $manifest['sql'] as $query )
|
||||
{
|
||||
$query = trim( $query );
|
||||
if ( $query )
|
||||
$this->db -> query( $query );
|
||||
}
|
||||
}
|
||||
|
||||
/* usuwanie plikow z manifestu */
|
||||
if ( !empty( $manifest['files']['deleted'] ) && is_array( $manifest['files']['deleted'] ) )
|
||||
{
|
||||
foreach ( $manifest['files']['deleted'] as $filePath )
|
||||
{
|
||||
$fullPath = '../' . $filePath;
|
||||
if ( file_exists( $fullPath ) )
|
||||
unlink( $fullPath );
|
||||
}
|
||||
}
|
||||
|
||||
/* usuwanie katalogow z manifestu */
|
||||
if ( !empty( $manifest['directories_deleted'] ) && is_array( $manifest['directories_deleted'] ) )
|
||||
{
|
||||
foreach ( $manifest['directories_deleted'] as $dirPath )
|
||||
{
|
||||
$fullPath = '../' . $dirPath;
|
||||
if ( is_dir( $fullPath ) )
|
||||
\S::delete_dir( $fullPath );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* legacy: aktualizacja bazy danych z _sql.txt */
|
||||
$sql = @file_get_contents( $baseUrl . '/ver_' . $ver . '_sql.txt' );
|
||||
if ( $sql )
|
||||
{
|
||||
$sql = explode( PHP_EOL, $sql );
|
||||
if ( is_array( $sql ) ) foreach ( $sql as $query )
|
||||
{
|
||||
$query = trim( $query );
|
||||
if ( $query )
|
||||
$this->db -> query( $query );
|
||||
}
|
||||
}
|
||||
|
||||
/* legacy: usuwanie zbednych plikow z _files.txt */
|
||||
$lines = @file_get_contents( $baseUrl . '/ver_' . $ver . '_files.txt' );
|
||||
if ( $lines )
|
||||
{
|
||||
$lines = explode( PHP_EOL, $lines );
|
||||
if ( is_array( $lines ) ) foreach ( $lines as $line )
|
||||
{
|
||||
if ( strpos( $line, 'F: ' ) !== false )
|
||||
{
|
||||
$delFile = substr( $line, 3, strlen( $line ) );
|
||||
if ( file_exists( $delFile ) )
|
||||
unlink( $delFile );
|
||||
}
|
||||
|
||||
if ( strpos( $line, 'D: ' ) !== false )
|
||||
{
|
||||
$delDir = substr( $line, 3, strlen( $line ) );
|
||||
if ( is_dir( $delDir ) )
|
||||
\S::delete_dir( $delDir );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* wgrywanie nowych plikow */
|
||||
$file_name = 'update.zip';
|
||||
|
||||
$path = pathinfo( realpath( $file_name ), PATHINFO_DIRNAME );
|
||||
$path = substr( $path, 0, strlen( $path ) - 5 );
|
||||
$zip = new \ZipArchive;
|
||||
$res = $zip -> open( $file_name );
|
||||
if ( $res === TRUE )
|
||||
{
|
||||
$zip -> extractTo( $path );
|
||||
$zip -> close();
|
||||
unlink( $file_name );
|
||||
}
|
||||
|
||||
$updateThis = fopen( '../libraries/version.ini', 'w' );
|
||||
fwrite( $updateThis, $ver );
|
||||
fclose( $updateThis );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
57
autoload/Domain/SeoAdditional/SeoAdditionalRepository.php
Normal file
57
autoload/Domain/SeoAdditional/SeoAdditionalRepository.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
namespace Domain\SeoAdditional;
|
||||
|
||||
class SeoAdditionalRepository
|
||||
{
|
||||
private $db;
|
||||
|
||||
public function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
public function elementDelete($elementId)
|
||||
{
|
||||
return $this->db->delete('pp_seo_additional', ['id' => (int)$elementId]);
|
||||
}
|
||||
|
||||
public function elementSave($id, $url, $status, $title, $keywords, $description, $text)
|
||||
{
|
||||
if (!$id)
|
||||
{
|
||||
if ($this->db->insert('pp_seo_additional', [
|
||||
'url' => $url,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'title' => $title,
|
||||
'keywords' => $keywords,
|
||||
'description' => $description,
|
||||
'text' => $text
|
||||
]))
|
||||
{
|
||||
\S::delete_cache();
|
||||
return $this->db->id();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->update('pp_seo_additional', [
|
||||
'url' => $url,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'title' => $title,
|
||||
'keywords' => $keywords,
|
||||
'description' => $description,
|
||||
'text' => $text
|
||||
], [
|
||||
'id' => (int)$id
|
||||
]);
|
||||
|
||||
\S::delete_cache();
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
|
||||
public function elementDetails($elementId)
|
||||
{
|
||||
return $this->db->get('pp_seo_additional', '*', ['id' => (int)$elementId]);
|
||||
}
|
||||
}
|
||||
@@ -6,98 +6,63 @@ class Releases
|
||||
public static function get_versions(): array
|
||||
{
|
||||
global $mdb;
|
||||
$rows = $mdb->select('pp_update_versions', '*', ['ORDER' => ['version' => 'DESC']]);
|
||||
if (!$rows) return [];
|
||||
foreach ($rows as &$row)
|
||||
$row['zip_exists'] = file_exists('../updates/' . self::zip_dir($row['version']) . '/ver_' . $row['version'] . '.zip');
|
||||
return $rows;
|
||||
$repo = new \Domain\Releases\ReleasesRepository($mdb);
|
||||
return $repo->getVersions();
|
||||
}
|
||||
|
||||
public static function promote(string $version): void
|
||||
{
|
||||
global $mdb;
|
||||
$mdb->update('pp_update_versions',
|
||||
['channel' => 'stable', 'promoted_at' => date('Y-m-d H:i:s')],
|
||||
['version' => $version]
|
||||
);
|
||||
$repo = new \Domain\Releases\ReleasesRepository($mdb);
|
||||
$repo->promote($version);
|
||||
}
|
||||
|
||||
public static function demote(string $version): void
|
||||
{
|
||||
global $mdb;
|
||||
$mdb->update('pp_update_versions',
|
||||
['channel' => 'beta', 'promoted_at' => null],
|
||||
['version' => $version]
|
||||
);
|
||||
$repo = new \Domain\Releases\ReleasesRepository($mdb);
|
||||
$repo->demote($version);
|
||||
}
|
||||
|
||||
public static function discover_versions(): int
|
||||
{
|
||||
global $mdb;
|
||||
$known = array_flip($mdb->select('pp_update_versions', 'version', []) ?: []);
|
||||
$zips = glob('../updates/*/ver_*.zip') ?: [];
|
||||
$added = 0;
|
||||
foreach ($zips as $path) {
|
||||
preg_match('/ver_([0-9.]+)\.zip$/', $path, $m);
|
||||
if (!$m) continue;
|
||||
$ver = $m[1];
|
||||
if (isset($known[$ver])) continue;
|
||||
$mdb->insert('pp_update_versions', [
|
||||
'version' => $ver,
|
||||
'channel' => 'beta',
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
$known[$ver] = true;
|
||||
$added++;
|
||||
}
|
||||
return $added;
|
||||
$repo = new \Domain\Releases\ReleasesRepository($mdb);
|
||||
return $repo->discoverVersions();
|
||||
}
|
||||
|
||||
public static function get_licenses(): array
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb->select('pp_update_licenses', '*', ['ORDER' => ['domain' => 'ASC']]) ?: [];
|
||||
$repo = new \Domain\Releases\ReleasesRepository($mdb);
|
||||
return $repo->getLicenses();
|
||||
}
|
||||
|
||||
public static function get_license(int $id): array
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb->get('pp_update_licenses', '*', ['id' => $id]) ?: [];
|
||||
$repo = new \Domain\Releases\ReleasesRepository($mdb);
|
||||
return $repo->getLicense($id);
|
||||
}
|
||||
|
||||
public static function save_license(array $data): void
|
||||
{
|
||||
global $mdb;
|
||||
$row = [
|
||||
'key' => trim($data['key'] ?? ''),
|
||||
'domain' => trim($data['domain'] ?? ''),
|
||||
'valid_to_date' => $data['valid_to_date'] ?: null,
|
||||
'valid_to_version' => $data['valid_to_version'] ?: null,
|
||||
'beta' => (int)(bool)($data['beta'] ?? 0),
|
||||
'note' => trim($data['note'] ?? ''),
|
||||
];
|
||||
if (!empty($data['id']))
|
||||
$mdb->update('pp_update_licenses', $row, ['id' => (int)$data['id']]);
|
||||
else
|
||||
$mdb->insert('pp_update_licenses', $row);
|
||||
$repo = new \Domain\Releases\ReleasesRepository($mdb);
|
||||
$repo->saveLicense($data);
|
||||
}
|
||||
|
||||
public static function delete_license(int $id): void
|
||||
{
|
||||
global $mdb;
|
||||
$mdb->delete('pp_update_licenses', ['id' => $id]);
|
||||
$repo = new \Domain\Releases\ReleasesRepository($mdb);
|
||||
$repo->deleteLicense($id);
|
||||
}
|
||||
|
||||
public static function toggle_beta(int $id): void
|
||||
{
|
||||
global $mdb;
|
||||
$license = $mdb->get('pp_update_licenses', ['id', 'beta'], ['id' => $id]);
|
||||
if ($license)
|
||||
$mdb->update('pp_update_licenses', ['beta' => $license['beta'] ? 0 : 1], ['id' => $id]);
|
||||
}
|
||||
|
||||
private static function zip_dir(string $version): string
|
||||
{
|
||||
return substr($version, 0, strlen($version) - (strlen($version) == 5 ? 2 : 1)) . '0';
|
||||
$repo = new \Domain\Releases\ReleasesRepository($mdb);
|
||||
$repo->toggleBeta($id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,51 +5,21 @@ class SeoAdditional
|
||||
public static function element_delete( $element_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> delete( 'pp_seo_additional', [ 'id' => (int)$element_id ] );
|
||||
$repo = new \Domain\SeoAdditional\SeoAdditionalRepository($mdb);
|
||||
return $repo->elementDelete($element_id);
|
||||
}
|
||||
|
||||
|
||||
public static function element_save( $id, $url, $status, $title, $keywords, $description, $text )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$id )
|
||||
{
|
||||
if ( $mdb -> insert( 'pp_seo_additional', [
|
||||
'url' => $url,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'title' => $title,
|
||||
'keywords' => $keywords,
|
||||
'description' => $description,
|
||||
'text' => $text
|
||||
] ) )
|
||||
{
|
||||
\S::delete_cache();
|
||||
return $mdb -> id();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_seo_additional', [
|
||||
'url' => $url,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'title' => $title,
|
||||
'keywords' => $keywords,
|
||||
'description' => $description,
|
||||
'text' => $text
|
||||
$repo = new \Domain\SeoAdditional\SeoAdditionalRepository($mdb);
|
||||
return $repo->elementSave($id, $url, $status, $title, $keywords, $description, $text);
|
||||
}
|
||||
|
||||
], [
|
||||
'id' => (int)$id
|
||||
] );
|
||||
|
||||
\S::delete_cache();
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
|
||||
public static function element_details( $element_id )
|
||||
{
|
||||
global $mdb;
|
||||
$result = $mdb -> get ( 'pp_seo_additional', '*', [ 'id' => (int)$element_id ] );
|
||||
return $result;
|
||||
global $mdb;
|
||||
$repo = new \Domain\SeoAdditional\SeoAdditionalRepository($mdb);
|
||||
return $repo->elementDetails($element_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,151 +6,7 @@ class Update
|
||||
public static function update()
|
||||
{
|
||||
global $mdb, $settings;
|
||||
|
||||
\S::delete_session( 'new-version' );
|
||||
|
||||
$versions = file_get_contents( 'http://www.cmspro.project-dc.pl/updates/versions.php?key=' . $settings['update_key'] );
|
||||
$versions = explode( PHP_EOL, $versions );
|
||||
|
||||
foreach ( $versions as $ver )
|
||||
{
|
||||
$ver = trim( $ver );
|
||||
if ( (float)$ver > (float)\S::get_version() )
|
||||
{
|
||||
if ( strlen( $ver ) == 5 )
|
||||
$dir = substr( $ver, 0, strlen( $ver ) - 2 ) . 0;
|
||||
else
|
||||
$dir = substr( $ver, 0, strlen( $ver ) - 1 ) . 0;
|
||||
|
||||
$baseUrl = 'http://www.cmspro.project-dc.pl/updates/' . $dir;
|
||||
|
||||
/* pobranie paczki ZIP */
|
||||
$file = file_get_contents( $baseUrl . '/ver_' . $ver . '.zip' );
|
||||
|
||||
$dlHandler = fopen( 'update.zip' , 'w' );
|
||||
if ( !fwrite( $dlHandler, $file ) )
|
||||
return false;
|
||||
fclose( $dlHandler );
|
||||
|
||||
if ( !file_exists( 'update.zip' ) )
|
||||
return false;
|
||||
|
||||
/* pobranie manifestu JSON (nowy system) lub fallback na legacy _sql.txt / _files.txt */
|
||||
$manifest = null;
|
||||
$manifestJson = @file_get_contents( $baseUrl . '/ver_' . $ver . '_manifest.json' );
|
||||
if ( $manifestJson )
|
||||
{
|
||||
if ( substr( $manifestJson, 0, 3 ) === "\xEF\xBB\xBF" )
|
||||
$manifestJson = substr( $manifestJson, 3 );
|
||||
$manifest = @json_decode( $manifestJson, true );
|
||||
}
|
||||
|
||||
if ( is_array( $manifest ) )
|
||||
{
|
||||
/* weryfikacja checksum SHA256 */
|
||||
if ( !empty( $manifest['checksum_zip'] ) )
|
||||
{
|
||||
$expectedHash = str_replace( 'sha256:', '', $manifest['checksum_zip'] );
|
||||
$actualHash = hash_file( 'sha256', 'update.zip' );
|
||||
if ( $expectedHash !== $actualHash )
|
||||
{
|
||||
unlink( 'update.zip' );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* aktualizacja bazy danych z manifestu */
|
||||
if ( !empty( $manifest['sql'] ) && is_array( $manifest['sql'] ) )
|
||||
{
|
||||
foreach ( $manifest['sql'] as $query )
|
||||
{
|
||||
$query = trim( $query );
|
||||
if ( $query )
|
||||
$mdb -> query( $query );
|
||||
}
|
||||
}
|
||||
|
||||
/* usuwanie plikow z manifestu */
|
||||
if ( !empty( $manifest['files']['deleted'] ) && is_array( $manifest['files']['deleted'] ) )
|
||||
{
|
||||
foreach ( $manifest['files']['deleted'] as $filePath )
|
||||
{
|
||||
$fullPath = '../' . $filePath;
|
||||
if ( file_exists( $fullPath ) )
|
||||
unlink( $fullPath );
|
||||
}
|
||||
}
|
||||
|
||||
/* usuwanie katalogow z manifestu */
|
||||
if ( !empty( $manifest['directories_deleted'] ) && is_array( $manifest['directories_deleted'] ) )
|
||||
{
|
||||
foreach ( $manifest['directories_deleted'] as $dirPath )
|
||||
{
|
||||
$fullPath = '../' . $dirPath;
|
||||
if ( is_dir( $fullPath ) )
|
||||
\S::delete_dir( $fullPath );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* legacy: aktualizacja bazy danych z _sql.txt */
|
||||
$sql = @file_get_contents( $baseUrl . '/ver_' . $ver . '_sql.txt' );
|
||||
if ( $sql )
|
||||
{
|
||||
$sql = explode( PHP_EOL, $sql );
|
||||
if ( is_array( $sql ) ) foreach ( $sql as $query )
|
||||
{
|
||||
$query = trim( $query );
|
||||
if ( $query )
|
||||
$mdb -> query( $query );
|
||||
}
|
||||
}
|
||||
|
||||
/* legacy: usuwanie zbednych plikow z _files.txt */
|
||||
$lines = @file_get_contents( $baseUrl . '/ver_' . $ver . '_files.txt' );
|
||||
if ( $lines )
|
||||
{
|
||||
$lines = explode( PHP_EOL, $lines );
|
||||
if ( is_array( $lines ) ) foreach ( $lines as $line )
|
||||
{
|
||||
if ( strpos( $line, 'F: ' ) !== false )
|
||||
{
|
||||
$delFile = substr( $line, 3, strlen( $line ) );
|
||||
if ( file_exists( $delFile ) )
|
||||
unlink( $delFile );
|
||||
}
|
||||
|
||||
if ( strpos( $line, 'D: ' ) !== false )
|
||||
{
|
||||
$delDir = substr( $line, 3, strlen( $line ) );
|
||||
if ( is_dir( $delDir ) )
|
||||
\S::delete_dir( $delDir );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* wgrywanie nowych plikow */
|
||||
$file_name = 'update.zip';
|
||||
|
||||
$path = pathinfo( realpath( $file_name ), PATHINFO_DIRNAME );
|
||||
$path = substr( $path, 0, strlen( $path ) - 5 );
|
||||
$zip = new \ZipArchive;
|
||||
$res = $zip -> open( $file_name );
|
||||
if ( $res === TRUE )
|
||||
{
|
||||
$zip -> extractTo( $path );
|
||||
$zip -> close();
|
||||
unlink( $file_name );
|
||||
}
|
||||
|
||||
$updateThis = fopen( '../libraries/version.ini', 'w' );
|
||||
fwrite( $updateThis, $ver );
|
||||
fclose( $updateThis );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
$repo = new \Domain\Releases\UpdateRepository($mdb, $settings);
|
||||
return $repo->update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,511 +4,21 @@ class Cron
|
||||
public static function automatic_update_sites()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> query( "SELECT id, url FROM projects WHERE automatic_update = 1 AND DATE_ADD( last_update, INTERVAL 1 WEEK ) <= '" . date( 'Y-m-d H:i:s' ) . "'" ) -> fetchAll();
|
||||
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$mdb -> delete( 'project_links_internal', [ 'AND' => [ 'project_id' => $row['id'], 'parent_id[!]' => null ] ] );
|
||||
$mdb -> delete( 'project_links_external', [ 'project_id' => $row['id'] ] );
|
||||
$mdb -> update( 'project_links_internal', [ 'visited' => 0 ], [ 'project_id' => $row['id'] ] );
|
||||
|
||||
$mdb -> update( 'projects', [ 'last_update' => date( 'Y-m-d H:i:s' ) ], [ 'id' => $row['id'] ] );
|
||||
|
||||
return [ 'status' => 'ok', 'msg' => 'Ponawiam sprawdzanie strony <a href="' . $row['url'] . '" target="_blank">' . $row['url'] . '</a>' ];
|
||||
}
|
||||
return [ 'status' => 'empty' ];
|
||||
$repo = new \Domain\Cron\CronRepository($mdb);
|
||||
return $repo->automaticUpdateSites();
|
||||
}
|
||||
|
||||
|
||||
public static function get_site_main_links()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> query( 'SELECT id, url FROM projects WHERE id NOT IN ( SELECT project_id FROM project_links_internal GROUP BY project_id ) AND enabled = 1 LIMIT 1' ) -> fetchAll();
|
||||
if ( is_array( $results ) and !empty ( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt( $ch, CURLOPT_URL, $row['url'] );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
|
||||
curl_setopt( $ch, CURLOPT_VERBOSE, 1 );
|
||||
curl_setopt( $ch, CURLOPT_TIMEOUT, 60 );
|
||||
curl_setopt( $ch, CURLOPT_HEADER, true );
|
||||
curl_setopt( $ch, CURLOPT_CAINFO, 'cacert.pem' );
|
||||
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
|
||||
curl_setopt( $ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.103 Safari/537.36' );
|
||||
$response = curl_exec( $ch );
|
||||
curl_close ( $ch );
|
||||
|
||||
if ( !curl_errno( $ch ) )
|
||||
{
|
||||
$mdb -> insert( 'project_links_internal', [
|
||||
'project_id' => $row['id'],
|
||||
'url' => $row['url'],
|
||||
'parent_id' => null
|
||||
] );
|
||||
|
||||
$doc = new DOMDocument;
|
||||
$doc -> loadHTML( $response );
|
||||
foreach ( $doc -> getElementsByTagName( 'a' ) as $link )
|
||||
{
|
||||
$url = $link -> getAttribute( 'href' );
|
||||
|
||||
if ( \S::is_url_internal( $row['url'], $url ) )
|
||||
{
|
||||
if ( strpos( $url, '#' ) !== false )
|
||||
$url = rtrim( substr( $url, 0, strpos( $url, '#' ) ), '?,#' );
|
||||
|
||||
$url = \S::modify_internal_link( $row['url'], $url );
|
||||
|
||||
if ( !filter_var( $url, FILTER_VALIDATE_URL ) === false and !$mdb -> count( 'project_links_internal', [ 'AND' => [ 'project_id' => $row['id'], 'url' => $url ] ] ) )
|
||||
{
|
||||
$mdb -> insert( 'project_links_internal', [
|
||||
'project_id' => $row['id'],
|
||||
'url' => $url
|
||||
] );
|
||||
}
|
||||
}
|
||||
}
|
||||
return [ 'status' => 'ok', 'msg' => 'Pobieram linki dla strony <a href="' . $row['url'] . '" target="_blank">' . $row['url'] . '</a>' ];
|
||||
}
|
||||
else
|
||||
return [ 'status' => 'ok', 'msg' => 'Błąd podczas pobierania strony <a href="' . $row['url'] . '" target="_blank">' . $row['url'] . '</a>' ];
|
||||
}
|
||||
return [ 'status' => 'empty' ];
|
||||
$repo = new \Domain\Cron\CronRepository($mdb);
|
||||
return $repo->getSiteMainLinks();
|
||||
}
|
||||
|
||||
|
||||
public static function get_site_other_links()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> query( 'SELECT '
|
||||
. 'pli.id, project_id, pli.url, p.url AS project_url '
|
||||
. 'FROM '
|
||||
. 'project_links_internal AS pli '
|
||||
. 'INNER JOIN projects AS p ON p.id = pli.project_id '
|
||||
. 'WHERE '
|
||||
. 'visited = 0 AND enabled = 1 '
|
||||
. 'LIMIT 1' ) -> fetchAll();
|
||||
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$url = parse_url( $row['url'] );
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
|
||||
curl_setopt( $ch, CURLOPT_VERBOSE, 1 );
|
||||
curl_setopt( $ch, CURLOPT_TIMEOUT, 60 );
|
||||
curl_setopt( $ch, CURLOPT_COOKIEFILE, 'temp/cookie.txt' );
|
||||
curl_setopt( $ch, CURLOPT_COOKIEJAR, 'temp/cookie.txt' );
|
||||
curl_setopt( $ch, CURLOPT_CAINFO, 'cacert.pem' );
|
||||
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
|
||||
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
|
||||
curl_setopt( $ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.103 Safari/537.36' );
|
||||
|
||||
curl_setopt( $ch, CURLOPT_URL, 'http://' . $url['host'] );
|
||||
$response = curl_exec( $ch );
|
||||
|
||||
curl_setopt( $ch, CURLOPT_URL, $row['url'] );
|
||||
$response = curl_exec( $ch );
|
||||
$content_type = curl_getinfo( $ch, CURLINFO_CONTENT_TYPE );
|
||||
$code = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
|
||||
curl_close ( $ch );
|
||||
|
||||
if ( !curl_errno( $ch ) and ( $code == 200 or $code == 301 ) and strpos( $content_type, 'text/html' ) !== false )
|
||||
{
|
||||
self::get_site_meta_title( $row['id'], $response );
|
||||
self::get_site_meta_keywords( $row['id'], $response );
|
||||
self::get_site_meta_description( $row['id'], $response );
|
||||
self::get_site_meta_robots( $row['id'], $response );
|
||||
self::get_site_meta_googlebot( $row['id'], $response );
|
||||
self::get_site_code_lenght( $row['id'], $response );
|
||||
self::get_site_text_lenght( $row['id'], $response );
|
||||
self::get_site_canonical( $row['id'], $response );
|
||||
self::get_table_exists( $row['id'], $response );
|
||||
self::get_iframe_exists( $row['id'], $response );
|
||||
self::get_h1_exists( $row['id'], $response );
|
||||
self::get_images_without_alt( $row['id'], $response );
|
||||
|
||||
/* pobranie linków ze strony */
|
||||
$doc = new DOMDocument;
|
||||
$doc -> loadHTML( $response );
|
||||
|
||||
foreach ( $doc -> getElementsByTagName( 'a' ) as $link )
|
||||
{
|
||||
$url = $link -> getAttribute( 'href' );
|
||||
|
||||
/* linki wewnętrzne na danej postronie */
|
||||
if ( \S::is_url_internal( $row['project_url'], $url ) )
|
||||
{
|
||||
if ( strpos( $url, '#' ) !== false )
|
||||
$url = rtrim( substr( $url, 0, strpos( $url, '#' ) ), '?,#' );
|
||||
|
||||
$url = \S::modify_internal_link( $row['project_url'], $url, $row['url'] );
|
||||
$info = pathinfo( $url );
|
||||
|
||||
if ( !filter_var( $url, FILTER_VALIDATE_URL ) === false and !in_array( strtolower( $info['extension'] ), \S::not_html_format() ) and !$mdb -> count( 'project_links_internal', [
|
||||
'AND' => [
|
||||
'project_id' => $row['project_id'],
|
||||
'url' => $url
|
||||
]
|
||||
] ) )
|
||||
{
|
||||
$mdb -> insert( 'project_links_internal', [
|
||||
'project_id' => $row['project_id'],
|
||||
'url' => $url,
|
||||
'visited' => 0,
|
||||
'parent_id' => $row['id'],
|
||||
'response' => $response
|
||||
] );
|
||||
}
|
||||
}
|
||||
/* linki zewnętrzne na danej podstronie */
|
||||
else
|
||||
{
|
||||
$link -> getAttribute( 'rel' ) == 'nofollow' ? $nofollow = 1 : $nofollow = 0;
|
||||
|
||||
$mdb -> insert( 'project_links_external', [
|
||||
'project_id' => $row['project_id'],
|
||||
'link_id' => $row['id'],
|
||||
'url' => $link -> getAttribute( 'href' ),
|
||||
'nofollow' => $nofollow,
|
||||
'title' => $link -> getAttribute( 'title' )
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
$mdb -> update( 'project_links_internal', [
|
||||
'visited' => 1,
|
||||
'content_type' => $content_type,
|
||||
'response_code' => $code,
|
||||
'response' => $response
|
||||
], [
|
||||
'id' => $row['id']
|
||||
] );
|
||||
|
||||
return [ 'status' => 'ok', 'msg' => 'Pobieram informacje dla strony <a href="' . $row['url'] . '" target="_blank">' . $row['url'] . '</a>' ];
|
||||
}
|
||||
else if ( $code == 404 or strpos( $content_type, 'text/html' ) === false )
|
||||
{
|
||||
$mdb -> update( 'project_links_internal', [
|
||||
'visited' => 1,
|
||||
'deleted' => 1,
|
||||
'content_type' => $content_type,
|
||||
'response_code' => $code
|
||||
], [
|
||||
'id' => $row['id']
|
||||
] );
|
||||
|
||||
return [ 'status' => 'ok', 'msg' => 'Pobieram informacje dla strony <a href="' . $row['url'] . '" target="_blank">' . $row['url'] . '</a>' ];
|
||||
}
|
||||
else if ( $code !== 200 and strpos( $content_type, 'text/html' ) !== false )
|
||||
{
|
||||
$mdb -> update( 'project_links_internal', [
|
||||
'visited' => 1,
|
||||
'content_type' => $content_type,
|
||||
'response_code' => $code,
|
||||
'response' => $response
|
||||
], [
|
||||
'id' => $row['id']
|
||||
] );
|
||||
|
||||
return [ 'status' => 'ok', 'msg' => 'Pobieram informacje dla strony <a href="' . $row['url'] . '" target="_blank">' . $row['url'] . '</a>' ];
|
||||
}
|
||||
else
|
||||
return [ 'status' => 'ok', 'msg' => 'Błąd podczas pobierania strony <a href="' . $row['url'] . '" target="_blank">' . $row['url'] . '</a>' ];
|
||||
}
|
||||
return [ 'status' => 'empty' ];
|
||||
}
|
||||
|
||||
static public function get_images_without_alt( $url_id, $response )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$doc = new DOMDocument;
|
||||
$doc -> loadHTML( $response );
|
||||
$images = $doc -> getElementsByTagName("img");
|
||||
|
||||
$have_images_without_alt = 0;
|
||||
foreach ( $images as $img )
|
||||
{
|
||||
if ( !$img -> getAttribute( 'alt' ) )
|
||||
$have_images_without_alt = 1;
|
||||
}
|
||||
|
||||
$mdb -> update( 'project_links_internal', [ 'have_images_without_alt' => $have_images_without_alt ], [ 'id' => $url_id ] );
|
||||
}
|
||||
|
||||
static public function get_table_exists( $url_id, $response )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$doc = new DOMDocument;
|
||||
$doc -> loadHTML( $response );
|
||||
$count = $doc -> getElementsByTagName("table");
|
||||
|
||||
$mdb -> update( 'project_links_internal', [ 'have_table' => $count -> length ? 1 : 0 ], [ 'id' => $url_id ] );
|
||||
}
|
||||
|
||||
static public function get_iframe_exists( $url_id, $response )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$doc = new DOMDocument;
|
||||
$doc -> loadHTML( $response );
|
||||
$count = $doc -> getElementsByTagName("iframe");
|
||||
|
||||
$mdb -> update( 'project_links_internal', [ 'have_iframe' => $count -> length ? 1 : 0 ], [ 'id' => $url_id ] );
|
||||
}
|
||||
|
||||
static public function get_h1_exists( $url_id, $response )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$doc = new DOMDocument;
|
||||
$doc -> loadHTML( $response );
|
||||
$count = $doc -> getElementsByTagName("h1");
|
||||
$mdb -> update( 'project_links_internal', [ 'have_h1' => $count -> length ? 1 : 0 ], [ 'id' => $url_id ] );
|
||||
}
|
||||
|
||||
public static function get_site_meta_title( $url_id, $response )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$title = '';
|
||||
|
||||
preg_match('/<title>([^>]*)<\/title>/si', $response, $match );
|
||||
|
||||
if ( isset( $match ) && is_array( $match ) && count( $match ) > 0 )
|
||||
$title = (string)strip_tags( $match[1] );
|
||||
|
||||
if ( !$title )
|
||||
{
|
||||
preg_match_all('/<[\s]*meta[\s]*name="og:?' . '([^>"]*)"?[\s]*' . 'content="?([^>"]*)"?[\s]*[\/]?[\s]*>/si', $response, $match);
|
||||
|
||||
if ( isset ( $match ) && is_array( $match ) && count( $match ) == 3 )
|
||||
{
|
||||
$originals = $match[0];
|
||||
$names = $match[1];
|
||||
$values = $match[2];
|
||||
|
||||
if ( count( $originals ) == count( $names ) && count( $names ) == count( $values ) )
|
||||
{
|
||||
$metaTags = array();
|
||||
for ( $i = 0, $limiti = count( $names ); $i < $limiti; $i++ )
|
||||
{
|
||||
$metaTags[ $names[$i] ] = array(
|
||||
'html' => htmlentities( $originals[$i] ),
|
||||
'value' => $values[$i]
|
||||
);
|
||||
}
|
||||
}
|
||||
$title = (string)$metaTags['title']['value'];
|
||||
}
|
||||
}
|
||||
|
||||
$mdb -> update( 'project_links_internal', [ 'title' => $title ], [ 'id' => $url_id ] );
|
||||
}
|
||||
|
||||
public static function get_site_canonical( $url_id, $response )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$doc = new DOMDocument;
|
||||
$doc -> loadHTML( $response );
|
||||
foreach ( $doc -> getElementsByTagName( 'link' ) as $link )
|
||||
{
|
||||
$rel = $link -> getAttribute( 'rel' );
|
||||
|
||||
if ( $rel == 'canonical' )
|
||||
{
|
||||
$canonical = $link -> getAttribute( 'href' );
|
||||
}
|
||||
}
|
||||
|
||||
$mdb -> update( 'project_links_internal', [ 'canonical' => $canonical ], [ 'id' => $url_id ] );
|
||||
}
|
||||
|
||||
public static function get_site_meta_keywords( $url_id, $response )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$meta_keywords = '';
|
||||
|
||||
preg_match_all( '/<[\s]*meta[\s]*name="?' . '([^>"]*)"?[\s]*' . 'content="?([^>"]*)"?[\s]*[\/]?[\s]*>/si', $response, $match );
|
||||
|
||||
if ( isset ( $match ) && is_array( $match ) && count( $match ) == 3 )
|
||||
{
|
||||
$originals = $match[0];
|
||||
$names = $match[1];
|
||||
$values = $match[2];
|
||||
|
||||
if ( count( $originals ) == count( $names ) && count( $names ) == count( $values ) )
|
||||
{
|
||||
$metaTags = array();
|
||||
for ( $i = 0, $limiti = count( $names ); $i < $limiti; $i++ )
|
||||
{
|
||||
$metaTags[ $names[$i] ] = array(
|
||||
'html' => htmlentities( $originals[$i] ),
|
||||
'value' => $values[$i]
|
||||
);
|
||||
}
|
||||
}
|
||||
$meta_keywords = (string)$metaTags['keywords']['value'];
|
||||
}
|
||||
|
||||
if ( !$meta_keywords )
|
||||
{
|
||||
preg_match_all( '/<[\s]*meta[\s]*property="og:?' . '([^>"]*)"?[\s]*' . 'content="?([^>"]*)"?[\s]*[\/]?[\s]*>/si', $response, $match );
|
||||
|
||||
if ( isset ( $match ) && is_array( $match ) && count( $match ) == 3 )
|
||||
{
|
||||
$originals = $match[0];
|
||||
$names = $match[1];
|
||||
$values = $match[2];
|
||||
|
||||
if ( count( $originals ) == count( $names ) && count( $names ) == count( $values ) )
|
||||
{
|
||||
$metaTags = array();
|
||||
for ( $i = 0, $limiti = count( $names ); $i < $limiti; $i++ )
|
||||
{
|
||||
$metaTags[ $names[$i] ] = array(
|
||||
'html' => htmlentities( $originals[$i] ),
|
||||
'value' => $values[$i]
|
||||
);
|
||||
}
|
||||
}
|
||||
$meta_keywords = (string)$metaTags['keywords']['value'];
|
||||
}
|
||||
}
|
||||
|
||||
$mdb -> update( 'project_links_internal', [ 'meta_keywords' => $meta_keywords ], [ 'id' => $url_id ] );
|
||||
}
|
||||
|
||||
public static function get_site_meta_description( $url_id, $response )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$meta_description = '';
|
||||
|
||||
preg_match_all('/<[\s]*meta[\s]*name="?' . '([^>"]*)"?[\s]*' . 'content="?([^>"]*)"?[\s]*[\/]?[\s]*>/si', $response, $match);
|
||||
|
||||
if ( isset ( $match ) && is_array( $match ) && count( $match ) == 3 )
|
||||
{
|
||||
$originals = $match[0];
|
||||
$names = $match[1];
|
||||
$values = $match[2];
|
||||
|
||||
if ( count( $originals ) == count( $names ) && count( $names ) == count( $values ) )
|
||||
{
|
||||
$metaTags = array();
|
||||
for ( $i = 0, $limiti = count( $names ); $i < $limiti; $i++ )
|
||||
{
|
||||
$metaTags[ $names[$i] ] = array(
|
||||
'html' => htmlentities( $originals[$i] ),
|
||||
'value' => $values[$i]
|
||||
);
|
||||
}
|
||||
}
|
||||
$meta_description = (string)$metaTags['description']['value'];
|
||||
}
|
||||
|
||||
if ( !$meta_description )
|
||||
{
|
||||
preg_match_all( '/<[\s]*meta[\s]*property="og:?' . '([^>"]*)"?[\s]*' . 'content="?([^>"]*)"?[\s]*[\/]?[\s]*>/si', $response, $match );
|
||||
|
||||
if ( isset ( $match ) && is_array( $match ) && count( $match ) == 3 )
|
||||
{
|
||||
$originals = $match[0];
|
||||
$names = $match[1];
|
||||
$values = $match[2];
|
||||
|
||||
if ( count( $originals ) == count( $names ) && count( $names ) == count( $values ) )
|
||||
{
|
||||
$metaTags = array();
|
||||
for ( $i = 0, $limiti = count( $names ); $i < $limiti; $i++ )
|
||||
{
|
||||
$metaTags[ $names[$i] ] = array(
|
||||
'html' => htmlentities( $originals[$i] ),
|
||||
'value' => $values[$i]
|
||||
);
|
||||
}
|
||||
}
|
||||
$meta_description = (string)$metaTags['description']['value'];
|
||||
}
|
||||
}
|
||||
|
||||
$mdb -> update( 'project_links_internal', [ 'meta_description' => $meta_description ], [ 'id' => $url_id ] );
|
||||
}
|
||||
|
||||
public static function get_site_meta_robots( $url_id, $response )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$meta_robots = '';
|
||||
|
||||
preg_match_all('/<[\s]*meta[\s]*name="?' . '([^>"]*)"?[\s]*' . 'content="?([^>"]*)"?[\s]*[\/]?[\s]*>/si', $response, $match);
|
||||
|
||||
if ( isset ( $match ) && is_array( $match ) && count( $match ) == 3 )
|
||||
{
|
||||
$originals = $match[0];
|
||||
$names = $match[1];
|
||||
$values = $match[2];
|
||||
|
||||
if ( count( $originals ) == count( $names ) && count( $names ) == count( $values ) )
|
||||
{
|
||||
$metaTags = array();
|
||||
for ( $i = 0, $limiti = count( $names ); $i < $limiti; $i++ )
|
||||
{
|
||||
$metaTags[ $names[$i] ] = array(
|
||||
'html' => htmlentities( $originals[$i] ),
|
||||
'value' => $values[$i]
|
||||
);
|
||||
}
|
||||
}
|
||||
$meta_robots = (string)$metaTags['robots']['value'];
|
||||
}
|
||||
|
||||
$mdb -> update( 'project_links_internal', [ 'meta_robots' => $meta_robots ], [ 'id' => $url_id ] );
|
||||
}
|
||||
|
||||
public static function get_site_meta_googlebot( $url_id, $response )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$meta_googlebot = '';
|
||||
|
||||
preg_match_all('/<[\s]*meta[\s]*name="?' . '([^>"]*)"?[\s]*' . 'content="?([^>"]*)"?[\s]*[\/]?[\s]*>/si', $response, $match);
|
||||
|
||||
if ( isset ( $match ) && is_array( $match ) && count( $match ) == 3 )
|
||||
{
|
||||
$originals = $match[0];
|
||||
$names = $match[1];
|
||||
$values = $match[2];
|
||||
|
||||
if ( count( $originals ) == count( $names ) && count( $names ) == count( $values ) )
|
||||
{
|
||||
$metaTags = array();
|
||||
for ( $i = 0, $limiti = count( $names ); $i < $limiti; $i++ )
|
||||
{
|
||||
$metaTags[ $names[$i] ] = array(
|
||||
'html' => htmlentities( $originals[$i] ),
|
||||
'value' => $values[$i]
|
||||
);
|
||||
}
|
||||
}
|
||||
$meta_googlebot = (string)$metaTags['googlebot']['value'];
|
||||
}
|
||||
|
||||
$mdb -> update( 'project_links_internal', [ 'meta_googlebot' => $meta_googlebot ], [ 'id' => $url_id ] );
|
||||
}
|
||||
|
||||
public static function get_site_code_lenght( $url_id, $response )
|
||||
{
|
||||
global $mdb;
|
||||
$mdb -> update( 'project_links_internal', [ 'code_lenght' => strlen( $response ) ], [ 'id' => $url_id ] );
|
||||
}
|
||||
|
||||
public static function get_site_text_lenght( $url_id, $response )
|
||||
{
|
||||
global $mdb;
|
||||
$mdb -> update( 'project_links_internal', [ 'text_lenght' => strlen( \S::strip_html_tags( $response ) ) ], [ 'id' => $url_id ] );
|
||||
$repo = new \Domain\Cron\CronRepository($mdb);
|
||||
return $repo->getSiteOtherLinks();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user