Fixed overlay for more templates
-
I made updates for core function of overlay mode. I thnik now it should work for nearly all templates. It is universal as long as possible.
// refactoring of function: S:\nfs\www\wp\www\wp-content\plugins\image-source-control-isc\isc.class.php public function get_image_by_url($url = '') { global $wpdb; if (empty($url)) { return 0; } $types = implode('|', $this->_allowedExtensions); /** * check for the format 'image-title-(e12452112-)300x200.jpg(?query…)' and removes * the image size * edit marks * additional query vars */ $newurl = esc_url(preg_replace("/(-e\d+){0,1}(-\d+x\d+){0,1}\.({$types})(.*)/i", '.${3}', $url)); // remove protocoll (http or https) // $newurl = str_ireplace(array('http:', 'https:'), '', $newurl); $newurl = preg_replace("#^(http)s?://[a-z0-9.-]+(/.+)$#i", '$2', $newurl); $newurl = "^.*".str_replace(".", '\.', $newurl)."$"; $sql = "SELECT ID FROM <code>".$wpdb->posts."</code>"; $sql .= " WHERE guid REGEXP %s"; $sql .= " AND post_type='attachment'"; $sql .= ' LIMIT 1'; // not escaped, because escaping already happened above $raw_query = $wpdb->prepare($sql, $newurl); $query = apply_filters('isc_get_image_by_url_query', $raw_query, $newurl); $id = $wpdb->get_var($query); return $id; } // S:\nfs\www\wp\www\wp-content\plugins\image-source-control-isc\public\public.php public function content_filter($content) { // display inline sources $options = $this->get_isc_options(); if (isset($options['display_type']) && is_array($options['display_type']) && in_array('overlay', $options['display_type'])) { //$pattern = '#(\[caption.*align="(.+)"[^\]*]{0,}\])? *(<a [^>]+>)? *(<img .*class=".*(alignleft|alignright|alignnone|aligncenter)??.*wp-image-(\d+)\D*".*src="(.+)".*/?'.'>).*(?(3)(?:</a>)|.*).*(?(1)(?:\[/caption\])|.*)#isU'; $pattern = '#<img .*src="(.+)".*/?'.'>#isU'; $count = preg_match_all($pattern, $content, $matches); if (FALSE !== $count) { for ($i = 0; $i < $count; $i++) { // get source $src = $matches[1][$i]; $id = $this->get_image_by_url($src); // don’t show caption for own image if admin choose not to do so if ($options['exclude_own_images']) { if (get_post_meta($id, 'isc_image_source_own', TRUE)) { continue; } } //die_dump($this->get_source_by_url($src)); if (!$source_string = $this->render_image_source_string($id)) { continue; } // add space if needed $options['source_pretext'] .= $options['source_pretext'] ? ' ' : ''; $source = '<p class="isc-source-text">'.$options['source_pretext'].$source_string.'</p>'; $old_content = $matches[0][$i]; // add own class with-source and/or if missing add unique class for image if (preg_match("/wp-image-".$id."/i", $old_content)) { $new_content = str_replace('wp-image-'.$id, 'wp-image-'.$id.' with-source', $old_content); } else { $new_content = str_replace('class="', 'class="wp-image-'.$id.' with-source ', $old_content); } // find alignment if (preg_match('/class="[^"]*(alignleft|alignright|alignnone|aligncenter)[^"]*"/i', $old_content, $alignment)) { $alignment = $alignment[1]; } else { $alignment = ''; } $content = str_replace($old_content, '<div id="isc_attachment_'.$id.'" class="isc-source '.$alignment.'"> '.$new_content.$source.'</div>', $content); } } }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Fixed overlay for more templates’ is closed to new replies.