Changeset 2526622
- Timestamp:
- 05/05/2021 12:00:26 PM (5 years ago)
- Location:
- makestories-helper/trunk
- Files:
-
- 7 edited
-
api/publish.php (modified) (9 diffs)
-
assets/css/ms-style.css (modified) (3 diffs)
-
config.php (modified) (2 diffs)
-
helpers.php (modified) (1 diff)
-
pages/category-structure.php (modified) (3 diffs)
-
templates/prepare-story-vars.php (modified) (1 diff)
-
templates/single-story.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
makestories-helper/trunk/api/publish.php
r2521956 r2526622 59 59 foreach ($parsed['media'] as $media) { 60 60 $imageurl = $media['url']; 61 if(strpos($imageurl, "ss.makestories.io/get") > 0){62 continue;63 }64 61 $name = $imageurl; 65 62 $nameExploded = explode("?",$imageurl); … … 76 73 $attach_id = false; 77 74 if( post_exists($atta_title) && !$forceUploadMedia ) { 78 $getAttachment = wp_get_attachment_by_post_name( $atta_title ); 75 if(wp_validate_boolean(apply_filters("ms_check_for_duplicate_media", true))){ 76 $getAttachment = wp_get_attachment_by_post_name( $atta_title ); 77 } 79 78 80 79 if($getAttachment) { … … 87 86 "into_else" => true, 88 87 "exists" => post_exists($atta_title), 89 "i" => wp_get_attachment_by_post_name( $atta_title ),90 88 ]; 91 89 } … … 107 105 } 108 106 109 if(ms_is_categories_enabled() ){107 if(ms_is_categories_enabled() && !isset($_REQUEST['is_republish'])){ 110 108 $category = ms_get_default_category(); 111 109 if(isset($_REQUEST['category']) && !empty($_REQUEST['category'])){ … … 195 193 $attach_id = false; 196 194 $forceUploadMedia = ms_get_options()['forceUploadMedia']; 197 $getAttachment = wp_get_attachment_by_post_name( $atta_title ); 195 if(wp_validate_boolean(apply_filters("ms_check_for_duplicate_media", true))){ 196 $getAttachment = wp_get_attachment_by_post_name( $atta_title ); 197 } 198 if(isset($_REQUEST['is_republish']) && wp_validate_boolean($_REQUEST['is_republish'])){ 199 $forceUploadMedia = true; 200 } 198 201 if( post_exists($atta_title) && !$forceUploadMedia && $getAttachment) { 199 202 $attach_id = $getAttachment->ID; 200 203 }else{ 204 205 $wp_filetype = wp_check_filetype(basename($filename), null ); 206 if(empty($wp_filetype['type'])){ 207 $wp_filetype = ms_find_filetype($imageurl); 208 } 209 210 if(isset($wp_filetype['ext']) && !empty($wp_filetype['ext']) && !msEndsWith($filename, $wp_filetype['ext'])){ 211 $filename = $filename.".".$wp_filetype['ext']; 212 } 213 201 214 $uploaddir = wp_upload_dir(); 202 215 $uploadfile = $uploaddir['path'] . '/' . $filename; … … 206 219 fclose($savefile); 207 220 208 $wp_filetype = wp_check_filetype(basename($filename), null );209 221 $attachment = array( 210 222 'post_mime_type' => $wp_filetype['type'], … … 214 226 ); 215 227 $attach_id = wp_insert_attachment( $attachment, $uploadfile ); 228 if($attach_id){ 229 $attach_data = wp_generate_attachment_metadata($attach_id, $uploadfile); 230 wp_update_attachment_metadata($attach_id, $attach_data); 231 } 216 232 } 217 233 … … 552 568 foreach (MS_DOMAINS as $domain){ 553 569 if(strpos($imageUrl, $domain) !== false){ 554 $media[] = $imageUrl;570 $media[] = ms_replace_domains($imageUrl); 555 571 break; 556 572 } … … 559 575 } 560 576 header("Content-Type: application/json"); 561 print_r(json_encode( $media));577 print_r(json_encode(array_unique($media))); 562 578 die(); 579 } 580 581 function ms_replace_domains($url){ 582 $url = str_replace("storage.googleapis.com/makestories-202705.appspot.com",MS_CDN_LINK, $url); 583 $url = str_replace("storage.googleapis.com/cdn-storyasset-link",MS_CDN_LINK, $url); 584 return $url; 563 585 } 564 586 -
makestories-helper/trunk/assets/css/ms-style.css
r2481763 r2526622 162 162 163 163 .default-stories h3 { 164 margin-bottom: 40px; 164 margin-bottom: 10px; 165 margin-top: 15px; 166 font-size: 2rem; 167 text-overflow: unset; 168 white-space: normal; 169 -webkit-box-orient: vertical; 170 display: -webkit-box; 171 -webkit-line-clamp: 2; 172 max-height: 3em; 173 overflow: hidden; 174 } 175 .default-stories p{ 176 margin-bottom: 0; 177 margin-top: 0; 178 font-size: 1.2rem; 179 text-decoration: none; 165 180 } 166 181 167 182 .story-thumb { 168 margin -bottom: 3%;169 margin- right: 0;183 margin: 0 15px; 184 margin-bottom: 15px; 170 185 transition: transform 0.5s; 171 flex-basis: 17%;186 flex-basis: 250px; 172 187 border-radius: 6px; 173 box-shadow: 0 0 8px 0 rgb(53 53 53 / 18%); 188 box-shadow: 0 0 8px 0 rgba(53,53,53,0.18); 189 padding: 12px; 190 } 191 192 .story-thumb a{ 193 text-decoration: none; 174 194 } 175 195 176 196 .story-thumb figure { 177 padding: 12px; 197 position: relative; 198 padding-bottom: 133%; 178 199 } 179 200 … … 185 206 .story-thumb img { 186 207 width: 100%; 187 border-radius: 6px; 208 border-radius: 4px; 209 position: absolute; 210 top: 0; 211 left: 0; 212 height: 100%; 213 object-fit: cover; 188 214 } 189 215 … … 211 237 @media screen and (max-width: 995px) { 212 238 .story-thumb { 213 flex-basis: 22%; 214 margin-right: 3.5%; 215 margin-bottom: 2rem; 216 } 217 218 .story-thumb:nth-child(6n) { 219 margin-right: 3.5%; 220 } 221 222 .story-thumb:nth-child(4n) { 223 margin-right: 0; 224 } 225 239 flex-basis: 225px; 240 } 241 .default-stories{ 242 width: 90%; 243 } 226 244 } 227 245 228 246 @media screen and (max-width: 550px) { 229 247 .story-thumb { 230 flex-basis: 45%; 231 margin-right: 8%; 232 margin-bottom: 2.5rem; 233 } 234 .story-thumb:nth-child(2n) { 235 margin-right: 0; 248 flex-basis: 40vw; 249 } 250 .default-stories{ 251 width: 94%; 236 252 } 237 253 } -
makestories-helper/trunk/config.php
r2521947 r2526622 10 10 define("MS_CDN_URL", "https://api.makestories.io/wp/".MS_PLUGIN_VERSION."/"); 11 11 12 12 /** 13 * Base server url 14 */ 15 define("MS_BASE_SERVER_URL", "https://server.makestories.io/"); 13 16 14 17 /** 15 18 * Url for viewing live preview of story being edited. 16 19 */ 17 define("MS_PREVIEW_URL", "https://server.makestories.io/preview/");20 define("MS_PREVIEW_URL", MS_BASE_SERVER_URL."preview/"); 18 21 19 22 /** … … 72 75 ]); 73 76 77 define("MS_CDN_LINK", "cdn.storyasset.link"); 78 74 79 define("MS_DOMAINS", [ 75 80 "storage.googleapis.com/makestories", 81 "storage.googleapis.com/cdn-storyasset-link", 76 82 "makestories.io", 77 83 "images.unsplash.com", -
makestories-helper/trunk/helpers.php
r2521947 r2526622 30 30 } 31 31 32 /** 33 * Function to get MIMETYPE of URL 34 * @param $imageurl string 35 * @return bool|string 36 */ 37 function ms_find_filetype($imageurl){ 38 $c = curl_init(MS_BASE_SERVER_URL.'get-image-meta?url='.$imageurl); 39 curl_setopt($c, CURLOPT_RETURNTRANSFER, true); 40 41 $details = curl_exec($c); 42 43 if (curl_error($c)){ 44 die(json_encode(["success" => false, "error" => "Error occurred while fetching image type."])); 45 } 46 // Get the status code 47 curl_close($c); 48 return json_decode($details, true); 49 } 50 51 function msEndsWith( $haystack, $needle ) { 52 $length = strlen( $needle ); 53 if( !$length ) { 54 return true; 55 } 56 return substr( $haystack, -$length ) === $needle; 57 } 32 58 function ms_get_options(){ 33 59 $options = get_option('mscpt_makestories_settings'); -
makestories-helper/trunk/pages/category-structure.php
r2521956 r2526622 88 88 </tr> 89 89 <tr> 90 <th scope="row"><label> Update Story Media</label></th>90 <th scope="row"><label></label></th> 91 91 <td> 92 92 <p class="submit"> … … 112 112 <p class="submit"> 113 113 <input type="submit" id="run-media-updates" name="submit" class="button button-primary" value="Run Updates"/> 114 </p> 115 </td> 116 </tr> 117 </table> 118 <table class="form-table" role="presentation"> 119 <tbody> 120 <tr> 121 <td colspan="2"> 122 <hr/> 123 </td> 124 </tr> 125 <tr> 126 <th scope="row"><label>Republish all stories</label></th> 127 <td> 128 <p class="description">This button re-publishes all the stories on your wordpress site. Helpful for bulk changes and in case you have not yet migrated from your old image urls.</p> 129 <p id="summary-republish"></p> 130 <p class="submit"> 131 <input type="submit" id="run-story-updates" name="submit" class="button button-primary" value="Republish All"/> 114 132 </p> 115 133 </td> … … 213 231 214 232 }); 233 234 $("#run-story-updates").on("click", function(){ 235 if(alreadyRunning){ 236 return false; 237 } 238 alreadyRunning = true; 239 let button = $(this); 240 let summary = $("#summary-republish"); 241 $.ajax({ 242 url: baseApiUrl, 243 data: { 244 _wpnonce: nonce, 245 action: "ms_get_published_posts_all", 246 }, 247 success: function(data){ 248 if(data && data.posts){ 249 let numOfPosts = Object.keys(data.posts).length; 250 let summaryPrepend = `Found ${numOfPosts} posts. Now fetching details and updating each post.`; 251 summary.html(summaryPrepend); 252 let chain = Promise.resolve(); 253 let index = 1; 254 Object.values(data.posts).map(({ post_id, story_id, title }) => { 255 chain = chain.then(() => republishStory(post_id, story_id, title, summaryPrepend+`<br>Publishing story ${index++} out of ${numOfPosts}`)); 256 }); 257 chain.then(() => { 258 summary.html("All stories updated. Thank you!") 259 }); 260 } 261 }, 262 error: function(){ 263 button.html("Run Updates"); 264 summary.html("Some error occurred while fetching story details. Please try again in some time!"); 265 } 266 }); 267 268 button.html("Running Updates..."); 269 summary.html("Fetching story details. Please do not leave the page"); 270 271 272 function republishStory(post_id, story, slug, summaryPrepend){ 273 return new Promise(resolve => { 274 $.ajax({ 275 url: baseApiUrl, 276 data: { 277 _wpnonce: nonce, 278 post_id, 279 story, 280 slug, 281 is_republish: true, 282 action: "ms_publish_post", 283 }, 284 success: function(response){ 285 const { media } = response || {}; 286 if(media && Array.isArray(media) && media.length){ 287 let chain = Promise.resolve(); 288 let index = 1; 289 media.map((url) => { 290 chain = chain.then(() => { 291 summary.html(`${summaryPrepend}.<br/>Downloading media: ${index++} out of ${media.length}`); 292 return replaceMediaInStory(url.imageurl, post_id) 293 }); 294 }); 295 chain.then(resolve); 296 }else{ 297 resolve(); 298 } 299 }, 300 error: (err) => { 301 resolve(); 302 }, 303 }); 304 }); 305 } 306 307 function replaceMediaInStory(imageurl, post_id){ 308 return new Promise(resolve => { 309 $.ajax({ 310 url: baseApiUrl, 311 data: { 312 _wpnonce: nonce, 313 action: "ms_upload_image_to_media_library", 314 post_id, 315 imageurl, 316 is_republish: true, 317 }, 318 success: resolve, 319 error: (err) => { 320 resolve(); 321 } 322 }); 323 }) 324 } 325 326 }); 215 327 }) 216 328 </script> -
makestories-helper/trunk/templates/prepare-story-vars.php
r2516559 r2526622 10 10 $logo = ''; 11 11 $title = get_the_title(); 12 $publishDate = get_the_date(); 12 13 try{ 13 14 if($publisherDetails && $parsedDetails = json_decode($publisherDetails, true)){ 14 $posterPortrait = $parsedDetails['poster-portrait-src'];15 $posterLandscape = $parsedDetails['poster-landscape-src'];16 $posterSquare = $parsedDetails['poster-square-src'];17 $logo = $parsedDetails['poster-square-src'];18 15 if($posterPortrait && !empty($posterPortrait)){ 19 16 $posterImage = $posterPortrait; 20 17 } 18 $posterPortrait = isset($parsedDetails['poster-portrait-src']) ? $parsedDetails['poster-portrait-src'] : $posterImage; 19 $posterLandscape = isset($parsedDetails['poster-landscape-src']) ? $parsedDetails['poster-landscape-src'] : $posterImage; 20 $posterSquare = isset($parsedDetails['poster-square-src']) ? $parsedDetails['poster-square-src'] : $posterImage; 21 $logo = isset($parsedDetails['poster-square-src']) ? $parsedDetails['poster-square-src'] : ''; 21 22 } 22 23 }catch (ErrorException $e){} -
makestories-helper/trunk/templates/single-story.php
r2516559 r2526622 4 4 <img src="<?php echo $posterImage ?>" /> 5 5 </figure> 6 <div class="bottom-text"> 7 <h3><?php echo $title; ?></h3> 8 <p><?php echo $publishDate; ?></p> 9 </div> 6 10 </a> 7 11 </div>
Note: See TracChangeset
for help on using the changeset viewer.