PluginProbe
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites / 3.3.3
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites v3.3.3
4.1.0 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 2.1.2 2.5.0 2.5.3 2.6.1 All 38 releases
← All changes | inc/layout/functions.php +88 -0 2.6.13.3.3 View file →
@@ -117,5 +117,93 @@
117 117 $registry = Component_Registry::instance();
118 118 return $registry::pages();
119 119 }
120 120
121 +/**
122 + * Gets the registered headers.
123 + *
124 + * @return array Array of registered headers.
125 + */
126 +function blockspare_get_headers() {
127 + $registry = Component_Registry::instance();
128 + return $registry::headers();
129 +}
130 +
131 +/**
132 + * Gets the registered footers.
133 + *
134 + * @return array Array of registered footers.
135 + */
136 +function blockspare_get_footers() {
137 + $registry = Component_Registry::instance();
138 + return $registry::footers();
139 +}
140 +
141 +function blockspare_get_templates() {
142 + $registry = Component_Registry::instance();
143 + return $registry::templates();
144 +}
145 +
146 +
147 +function blockspare_import_images_replace_url($content =''){
148 +
149 + preg_match_all( '#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $content, $match );
150 + $all_links = array_unique( $match[0] );
151 +
152 +
153 + if ( empty( $all_links ) ) {
154 + return $content;
155 + };
156 + $link_mapping = array();
157 + $image_links = array();
158 + $other_links = array();
159 + foreach ( $all_links as $key => $link ) {
160 + if ( blockspare_block_templates_is_valid_image( $link ) ) {
161 + if (
162 + false === strpos( $link, '-150x' ) &&
163 + false === strpos( $link, '-300x' ) &&
164 + false === strpos( $link, '-1024x' )
165 + ) {
166 + $image_links[] = $link;
167 + }
168 + } else {
169 +
170 +
171 + $other_links[] = $link;
172 + }
173 + }
174 +
175 +
176 + if ( ! empty( $image_links ) ) {
177 + foreach ( $image_links as $key => $image_url ) {
178 + // Download remote image.
179 + $image = array(
180 + 'url' => $image_url,
181 + 'id' => 0,
182 + );
183 + $downloaded_image = Blockspare_Design_Image_Importer::get_instance()->blockspare_import( $image );
184 +
185 +
186 + $link_mapping[ $image_url ] = $downloaded_image['url'];
187 + }
188 + }
189 + foreach ( $link_mapping as $old_url => $new_url ) {
190 + $content = str_replace( $old_url, $new_url, $content );
191 +
192 + // Replace the slashed URLs if any exist.
193 + $old_url = str_replace( '/', '/\\', $old_url );
194 + $new_url = str_replace( '/', '/\\', $new_url );
195 + $content = str_replace( $old_url, $new_url, $content );
196 + }
197 +
198 + return $content;
199 +
200 +
201 +
202 +
203 +}
204 +
205 +function blockspare_block_templates_is_valid_image( $link = '' ) {
206 + return preg_match( '/^((https?:\/\/)|(www\.))([a-z0-9-].?)+(:[0-9]+)?\/[\w\-]+\.(jpg|png|gif|jpeg)\/?$/i', $link );
207 +}
208 +
121 209