Skip to content

Commit

Permalink
Update ExternalDetector.php
Browse files Browse the repository at this point in the history
Avoids edge case where PostID does not exist
  • Loading branch information
pbrotherton authored Oct 25, 2022
1 parent 339f696 commit e26e782
Showing 1 changed file with 32 additions and 30 deletions.
62 changes: 32 additions & 30 deletions source/php/ExternalDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,44 +106,46 @@ public function lookForBrokenLinks($postId = null, $url = null)
}

/* START MODULE SUPPORT */
$modules = array();
$sql = "select meta_value from $wpdb->postmeta where meta_key='modularity-modules' and post_id = $postId";
$modularity = $wpdb->get_results($sql);
foreach($modularity as $module) {
if (is_numeric($postId)) {
$modules = array();
$sql = "select meta_value from $wpdb->postmeta where meta_key='modularity-modules' and post_id = $postId";
$modularity = $wpdb->get_results($sql);
foreach($modularity as $module) {
$data = unserialize($module->meta_value);
$keys = array_keys($data);
foreach($keys as $k) {
$modules[] = array_column($data[$k], 'postid');
$modules[] = array_column($data[$k], 'postid');
}
}
$modules = array_merge(...array_values($modules));
foreach($modules as $mid) {
$meta = get_post_meta($mid, $key = '', $single = false );
if(isset($meta['data']) && $meta['data'][0] > 0) {
for($i = 0; $i < $meta['data'][0]; $i++) {
$metakey = "data_".$i."_post_content";
preg_match_all('/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i', $meta[$metakey][0], $matches);
foreach($matches[0] as $url) {
if (!$this->isBroken($url)) {
continue;
}
$modules = array_merge(...array_values($modules));
foreach($modules as $mid) {
$meta = get_post_meta($mid, $key = '', $single = false );
if(isset($meta['data']) && $meta['data'][0] > 0) {
for($i = 0; $i < $meta['data'][0]; $i++) {
$metakey = "data_".$i."_post_content";
preg_match_all('/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i', $meta[$metakey][0], $matches);
foreach($matches[0] as $url) {
if (!$this->isBroken($url)) {
continue;
}
$foundUrls[] = array(
'post_id' => $postId,
'url' => $url
);
}
$foundUrls[] = array(
'post_id' => $postId,
'url' => $url
);
}
}
}
$mpost = get_post($mid);
preg_match_all('/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i', $mpost->post_content, $matches);
foreach($matches[0] as $url) {
if (!$this->isBroken($url)) {
continue;
$mpost = get_post($mid);
preg_match_all('/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i', $mpost->post_content, $matches);
foreach($matches[0] as $url) {
if (!$this->isBroken($url)) {
continue;
}
$foundUrls[] = array(
'post_id' => $postId,
'url' => $url
);
}
$foundUrls[] = array(
'post_id' => $postId,
'url' => $url
);
}
}
/* END MODULE SUPPORT */
Expand Down

0 comments on commit e26e782

Please sign in to comment.