Changeset 2516559
- Timestamp:
- 04/16/2021 09:40:27 PM (5 years ago)
- Location:
- makestories-helper/trunk
- Files:
-
- 2 added
- 10 edited
-
api/publish.php (modified) (6 diffs)
-
assets/js/ms-script.js (modified) (1 diff)
-
config.php (modified) (1 diff)
-
hooks.php (modified) (3 diffs)
-
shortcode.php (modified) (2 diffs)
-
taxonomy-ms_story_category.php (modified) (1 diff)
-
templates/archive-stories.php (modified) (1 diff)
-
templates/editor-full.php (modified) (2 diffs)
-
templates/editor-head.php (modified) (1 diff)
-
templates/ms-post-by-category.php (modified) (1 diff)
-
templates/prepare-story-vars.php (added)
-
templates/single-story.php (added)
Legend:
- Unmodified
- Added
- Removed
-
makestories-helper/trunk/api/publish.php
r2490587 r2516559 36 36 37 37 include_once( ABSPATH . 'wp-admin/includes/image.php' ); 38 $forceUploadMedia = ms_get_options()['forceUploadMedia'];39 38 if( ! ( function_exists( 'wp_get_attachment_by_post_name' ) ) ) { 40 39 function wp_get_attachment_by_post_name( $post_name ) { … … 54 53 } 55 54 } 55 $mediaLinksToDownload = []; 56 56 // Uploading media to media library of wordpress 57 $forceUploadMedia = ms_get_options()['forceUploadMedia']; 57 58 foreach ($parsed['media'] as $media) { 58 59 $imageurl = $media['url']; … … 81 82 82 83 } else { 83 $uploaddir = wp_upload_dir(); 84 $uploadfile = $uploaddir['path'] . '/' . $filename; 85 $contents= file_get_contents("https://beta.makestories.io/image-proxy?url=".urlencode($imageurl)); 86 $savefile = fopen($uploadfile, 'w'); 87 fwrite($savefile, $contents); 88 fclose($savefile); 89 90 $wp_filetype = wp_check_filetype(basename($filename), null ); 91 $attachment = array( 92 'post_mime_type' => $wp_filetype['type'], 93 'post_title' => $atta_title, 94 'post_content' => '', 95 'post_status' => 'inherit', 96 ); 97 98 $attach_id = wp_insert_attachment( $attachment, $uploadfile ); 84 $mediaLinksToDownload[] = [ 85 "imageurl" => $imageurl, 86 "filename" => $filename, 87 "atta_title" => $atta_title, 88 ]; 99 89 } 100 90 if($attach_id){ … … 127 117 json_encode( 128 118 getMSPostDataToSend( 129 get_post($post) 119 get_post($post), 120 [ 121 "media" => $mediaLinksToDownload 122 ] 130 123 ) 131 124 ) 132 125 ); 133 die(); 134 } 135 die(json_encode(["success" => false, "error" => "Invalid details provided!"])); 126 wp_die(); 127 } 128 wp_die(json_encode(["success" => false, "error" => "Invalid details provided!"])); 129 } 130 131 add_action("wp_ajax_ms_upload_image_to_media_library", "ms_upload_image_to_media_library"); 132 add_action("wp_ajax_nopriv_ms_upload_image_to_media_library", "ms_upload_image_to_media_library"); 133 134 function ms_upload_image_to_media_library(){ 135 ms_protect_ajax_route(); 136 header("Content-Type: application/json"); 137 $replaced = false; 138 if( 139 isset($_REQUEST['imageurl']) && 140 isset($_REQUEST['filename']) && 141 isset($_REQUEST['atta_title']) && 142 isset($_REQUEST['post_id']) 143 ){ 144 $imageurl = $_REQUEST['imageurl']; 145 $filename = $_REQUEST['filename']; 146 $atta_title = $_REQUEST['atta_title']; 147 $postId = $_REQUEST['post_id']; 148 include_once( ABSPATH . 'wp-admin/includes/image.php' ); 149 if( ! ( function_exists( 'wp_get_attachment_by_post_name' ) ) ) { 150 function wp_get_attachment_by_post_name( $post_name ) { 151 $args = array( 152 'posts_per_page' => 1, 153 'post_type' => 'attachment', 154 'name' => trim( $post_name ), 155 ); 156 157 $get_attachment = new WP_Query( $args ); 158 159 if ( ! $get_attachment || ! isset( $get_attachment->posts, $get_attachment->posts[0] ) ) { 160 return false; 161 } 162 163 return $get_attachment->posts[0]; 164 } 165 } 166 167 $attach_id = false; 168 $forceUploadMedia = ms_get_options()['forceUploadMedia']; 169 $getAttachment = wp_get_attachment_by_post_name( $atta_title ); 170 if( post_exists($atta_title) && !$forceUploadMedia && $getAttachment) { 171 $attach_id = $getAttachment->ID; 172 }else{ 173 $uploaddir = wp_upload_dir(); 174 $uploadfile = $uploaddir['path'] . '/' . $filename; 175 $contents= file_get_contents($imageurl); 176 $savefile = fopen($uploadfile, 'w'); 177 fwrite($savefile, $contents); 178 fclose($savefile); 179 180 $wp_filetype = wp_check_filetype(basename($filename), null ); 181 $attachment = array( 182 'post_mime_type' => $wp_filetype['type'], 183 'post_title' => $atta_title, 184 'post_content' => '', 185 'post_status' => 'inherit', 186 ); 187 $attach_id = wp_insert_attachment( $attachment, $uploadfile ); 188 } 189 190 if($attach_id){ 191 // Get permalink of media library 192 $permalink = wp_get_attachment_url($attach_id); 193 $post = get_post($postId); 194 $html = $post->post_content; 195 // Replace permalink of image with html 196 $html = str_ireplace($imageurl, $permalink, $html); 197 $replaced = true; 198 $updated = wp_update_post([ 199 "post_content" => $html, 200 "ID" => $postId, 201 ]); 202 } 203 } 204 echo json_encode([ 205 "replaced" => $replaced, 206 ]); 207 wp_die(); 208 136 209 } 137 210 … … 284 357 } 285 358 286 function getMSPostDataToSend($post){ 359 function getMSPostDataToSend($post, $toReturn = []){ 360 if(!is_array($toReturn)){ 361 $toReturn = []; 362 } 287 363 $category = []; 288 364 $terms = wp_get_post_terms($post->ID, MS_TAXONOMY); … … 290 366 $category[] = $term->name; 291 367 } 292 return [293 "id" => $post->ID,294 "lastUpdated" => strtotime($post->post_modified),295 "permalink" => get_post_permalink($post->ID),296 "name" => $post->post_name,297 "category" => $category,298 ];299 } 368 return array_merge([ 369 "id" => $post->ID, 370 "lastUpdated" => strtotime($post->post_modified), 371 "permalink" => get_post_permalink($post->ID), 372 "name" => $post->post_name, 373 "category" => $category, 374 ], $toReturn); 375 } -
makestories-helper/trunk/assets/js/ms-script.js
r2481763 r2516559 1 if (typeof $ === "undefined" && typeof jQuery === "function") { 2 $ = jQuery; 3 } 4 $(document).on('ready', function () { 5 if (typeof $ === "undefined" && typeof jQuery === "function") { 6 $ = jQuery; 7 } 8 let sliderWidth = $('.story-curousal').width(); 9 let slideNo = 5; 1 10 2 if(typeof $ === "undefined" && typeof jQuery === "function"){ 3 $ = jQuery; 4 } 11 if (sliderWidth < 587) { 12 slideNo = 1; 13 } else if (sliderWidth < 587) { 14 slideNo = 2; 15 } else if (sliderWidth < 761) { 16 slideNo = 3; 17 } else if (sliderWidth < 979) { 18 slideNo = 4; 19 } 5 20 6 $( document ).on('ready', function(){ 7 let sliderWidth = $('.story-curousal').width(); 8 let slideNo = 5; 21 // Curousal for all publishes stories 22 $('.story-curousal').slick({ 23 slidesToShow: slideNo, 24 slidesToScroll: 1, 25 autoplay: true, 26 autoplaySpeed: 2000, 27 fade: false, 28 responsive: [ 29 { 30 breakpoint: 550, 31 settings: { 32 centerMode: true, 33 } 34 } 35 ] 36 }); 9 37 10 // $(window).on('resize', function() { 11 if(sliderWidth < 587) { 12 slideNo = 1; 13 } else if(sliderWidth < 587) { 14 slideNo = 2; 15 } else if(sliderWidth < 761) { 16 slideNo = 3; 17 } else if(sliderWidth < 979) { 18 slideNo = 4; 19 } 20 // }) 21 22 // Curousal for all publishes stories 23 $('.story-curousal').slick({ 24 slidesToShow: slideNo, 25 slidesToScroll: 1, 26 autoplay: true, 27 autoplaySpeed: 2000, 28 fade: false, 29 responsive: [ 30 { 31 breakpoint: 550, 32 settings: { 33 centerMode: true, 34 } 35 } 36 ] 37 }); 38 $story = ''; 39 $default = ''; 38 40 39 $story = ''; 40 $default = ''; 41 // Get value on form submit 42 $('.category-allow-form').on('submit', function (e) { 43 e.preventDefault(); 41 44 42 // Get value on form submit 43 $('.category-allow-form').on('submit', function(e) { 44 e.preventDefault(); 45 46 $story = $('.category').val(); 47 $default = $('.default').val(); 45 $story = $('.category').val(); 46 $default = $('.default').val(); 48 47 49 }) 50 }) 48 }); 51 49 52 // Load more functionality 53 jQuery(document).ready( function($) { 54 let ajaxUrl = $('#ajax-posts').attr('data-ajax'); 55 let post_per_page = $('#ajax-posts').attr('data-posts'); 56 let page = 5; 57 let ppp = post_per_page; 50 // Load more functionality 51 let ajaxUrl = $('#ajax-posts').attr('data-ajax'); 52 let post_per_page = $('#ajax-posts').attr('data-posts'); 53 let page = 1; 54 let ppp = parseInt(post_per_page); 58 55 59 $("#more_posts").on("click", function() {56 $("#more_posts").on("click", function () { 60 57 61 // When btn is pressed.62 $(this).attr("disabled", true);58 // When btn is pressed. 59 $(this).attr("disabled", true); 63 60 64 // Disable the button, temp. 65 $.post(ajaxUrl, { 66 action: "more_post_ajax", 67 offset: (page * ppp) + 1, 68 ppp: ppp, 69 beforeSend: function (jqXHR) { 70 $('body').addClass('ms_loading'); 71 }, 72 }) 73 .success(function(posts) { 74 let post_length = posts.length; 75 if(post_length > 0) { 76 page++; 77 $("#ajax-posts").append(posts); 78 // CHANGE THIS! 79 $("#more_posts").attr("disabled", false); 80 } else { 81 $('body').addClass('ms_no_more_posts'); 82 } 83 $('body').removeClass('ms_loading'); 61 // Disable the button, temp. 62 $.post(ajaxUrl, { 63 action: "more_post_ajax", 64 offset: (page * ppp), 65 ppp: ppp, 66 beforeSend: function () { 67 $('body').addClass('ms_loading'); 68 }, 69 }) 70 .success(function (posts) { 71 let post_length = posts.length; 72 if (post_length > 0) { 73 page++; 74 $("#ajax-posts").append(posts); 75 // CHANGE THIS! 76 $("#more_posts").attr("disabled", false); 77 } else { 78 $('body').addClass('ms_no_more_posts'); 79 } 80 $('body').removeClass('ms_loading'); 81 }); 84 82 }); 85 }); 86 }); 83 }) -
makestories-helper/trunk/config.php
r2498952 r2516559 1 1 <?php 2 /** 3 * Version of plugin in use 4 */ 5 define("MS_PLUGIN_VERSION", "2.2"); 6 2 7 /** 3 8 * URL From where the main editor compiled files and other assets would be served 4 9 */ 5 define("MS_CDN_URL", "https://api.makestories.io/wp/ 2.1/");10 define("MS_CDN_URL", "https://api.makestories.io/wp/".MS_PLUGIN_VERSION."/"); 6 11 7 12 -
makestories-helper/trunk/hooks.php
r2481763 r2516559 103 103 if ($post && $post->post_type == MS_POST_TYPE && is_singular(MS_POST_TYPE)) { 104 104 //If it is a story, then show the story html 105 print_r( $post->post_content);105 print_r(apply_filters("ms_story_html", $post->post_content)); 106 106 die(); 107 107 } … … 212 212 } 213 213 else if( is_tax(MS_TAXONOMY) ) { 214 // require(mscpt_getTemplatePath("archive-stories.php"));215 214 $theme_files = '/taxonomy-ms_story_category.php'; 216 215 if ( file_exists(get_template_directory() . $theme_files) ) { 217 216 return get_template_directory() . $theme_files; 218 217 } else { 219 return MS_PLUGIN_BASE_PATH . '/taxonomy-ms_story_category.php';218 return MS_PLUGIN_BASE_PATH . $theme_files; 220 219 } 221 220 } … … 241 240 $out = ''; 242 241 243 while ($loop->have_posts()) { $loop->the_post(); 244 $permalink = get_the_permalink(); 245 $id = get_the_id(); 246 $storyId = get_post_meta($id, "story_id", true); 247 248 $out .= '<div class="story-thumb"> 249 <a href="'.$permalink.'" target="_blank"><figure> 250 <img src="https://ss.makestories.io/get?story='. $storyId .'" /> 251 </figure></a></div>'; 242 while ($loop->have_posts()) { $loop->the_post(); 243 include mscpt_getTemplatePath("prepare-story-vars.php"); 244 include mscpt_getTemplatePath("single-story.php"); 252 245 } 253 246 -
makestories-helper/trunk/shortcode.php
r2481763 r2516559 21 21 22 22 $loop = new WP_Query($args); 23 while ($loop->have_posts()) : $loop->the_post(); 24 $permalink = get_the_permalink(); 25 $id = get_the_id(); 26 $storyId = get_post_meta($id, "story_id", true); 27 28 require(mscpt_getTemplatePath('ms-published-post.php')); 29 endwhile; 23 while ($loop->have_posts()) : $loop->the_post(); 24 include mscpt_getTemplatePath("prepare-story-vars.php"); 25 include mscpt_getTemplatePath("single-story.php"); 26 endwhile; 30 27 wp_reset_postdata(); ?> 31 28 </div> … … 49 46 $cat_id = $attr['category_id']; 50 47 $int_cat = (int)$cat_id; 48 $term = get_term($int_cat,MS_TAXONOMY); 49 $args = [ 50 'post_type' => MS_POST_TYPE, 51 'posts_per_page' => -1, 52 'offset'=> 0, 53 "tax_query" => array( 54 array( 55 "taxonomy" => MS_TAXONOMY, 56 "field" => "term_id", 57 "terms" => $int_cat 58 )) 59 ]; 60 $loop = new WP_Query($args); 51 61 ob_start(); 52 ?> 53 <section class="default-stories"> 54 <h3><?php $term = get_term($int_cat,MS_TAXONOMY); echo $term->name; ?></h3> 55 <div id="ajax-posts-cat" data-cat="<?php echo $int_cat; ?>" data-posts="<?php echo $default_posts_per_page; ?>" class="stories-group" data-ajax="<?php echo $getAjaxUrl; ?>" class="row"> 56 <?php 57 $postsPerPage = $default_posts_per_page; 58 $args = [ 59 'post_type' => MS_POST_TYPE, 60 'posts_per_page' => -1, 61 "tax_query" => array( 62 array( 63 "taxonomy" => MS_TAXONOMY, 64 "field" => "term_id", 65 "terms" => $int_cat 66 )) 67 ]; 68 69 $loop = new WP_Query($args); 70 while ($loop->have_posts()) : $loop->the_post(); 71 $permalink = get_the_permalink(); 72 $id = get_the_id(); 73 $storyId = get_post_meta($id, "story_id", true); 74 require(mscpt_getTemplatePath('ms-post-by-category.php')); 75 endwhile; 76 wp_reset_postdata(); ?> 77 </div> 78 </section> <?php 62 require(mscpt_getTemplatePath('ms-post-by-category.php')); 79 63 return ob_get_clean(); 80 64 } -
makestories-helper/trunk/taxonomy-ms_story_category.php
r2481773 r2516559 4 4 $category_id = $category->term_id; 5 5 $int_cat = (int)$category_id; 6 7 $args = [ 8 'post_type' => MS_POST_TYPE, 9 'posts_per_page' => -1, 10 'offset'=> 0, 11 "tax_query" => array( 12 array( 13 "taxonomy" => MS_TAXONOMY, 14 "field" => "term_id", 15 "terms" => $int_cat 16 )) 17 ]; 18 19 $loop = new WP_Query($args); 6 20 ?> 7 8 21 <section class="default-stories"> 9 22 <h3><?php $term = get_term($int_cat,MS_TAXONOMY); echo $term->name; ?></h3> 10 23 <div class="stories-group"> 11 <?php $args = [ 12 'post_type' => MS_POST_TYPE, 13 'posts_per_page' => -1, 14 'offset'=> 0, 15 "tax_query" => array( 16 array( 17 "taxonomy" => MS_TAXONOMY, 18 "field" => "term_id", 19 "terms" => $int_cat 20 )) 21 ]; 22 23 $loop = new WP_Query($args); 24 25 while ($loop->have_posts()) : $loop->the_post(); 26 $permalink = get_the_permalink(); 27 $id = get_the_id(); 28 $storyId = get_post_meta($id, "story_id", true); ?> 29 30 <div class="story-thumb"> 31 <a href="<?php echo $permalink; ?>" target="_blank"> 32 <figure> 33 <img src="https://ss.makestories.io/get?story=<?php echo $storyId; ?>" /> 34 </figure> 35 </a> 36 </div> 37 38 <?php endwhile; 39 wp_reset_postdata(); ?> 24 <?php 25 while ($loop->have_posts()) : $loop->the_post(); 26 include mscpt_getTemplatePath("prepare-story-vars.php"); 27 include mscpt_getTemplatePath("single-story.php"); 28 endwhile; 29 wp_reset_postdata(); 30 ?> 40 31 </div> 41 32 </section> -
makestories-helper/trunk/templates/archive-stories.php
r2481773 r2516559 14 14 $loop = new WP_Query($args); 15 15 16 while ($loop->have_posts()) : $loop->the_post(); 17 $permalink = get_the_permalink(); 18 $id = get_the_id(); 19 $storyId = get_post_meta($id, "story_id", true); ?> 20 21 <div class="story-thumb"> 22 <a href="<?php echo $permalink; ?>" target="_blank"> 23 <figure> 24 <img src="https://ss.makestories.io/get?story=<?php echo $storyId; ?>" /> 25 </figure> 26 </a> 27 </div> 28 29 <?php endwhile; 16 while ($loop->have_posts()) : $loop->the_post(); 17 include mscpt_getTemplatePath("prepare-story-vars.php"); 18 include mscpt_getTemplatePath("single-story.php"); 19 endwhile; 30 20 wp_reset_postdata(); ?> 31 21 </div> -
makestories-helper/trunk/templates/editor-full.php
r2404028 r2516559 9 9 content="MakeStories - Web Stories Builder" 10 10 /> 11 <!--12 manifest.json provides metadata used when your web app is installed on a13 user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/14 -->15 11 <script async src="https://cdn.ampproject.org/v0.js"></script> 16 12 <script async custom-element="amp-facebook" src="https://cdn.ampproject.org/v0/amp-facebook-0.1.js"></script> … … 34 30 </script> 35 31 <script type="text/javascript">window.$crisp=[];window.CRISP_WEBSITE_ID="ba635223-d68b-476d-be2f-44e216b447eb";(function(){d=document;s=d.createElement("script");s.src="https://client.crisp.chat/l.js";s.async=1;d.getElementsByTagName("head")[0].appendChild(s);})();</script> 36 <!--37 Notice the use of %PUBLIC_URL% in the tags above.38 It will be replaced with the URL of the `public` folder during the build.39 Only files inside the `public` folder can be referenced from the HTML.40 41 Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will42 work correctly both with client-side routing and a non-root public URL.43 Learn how to configure a non-root public URL by running `npm run build`.44 -->45 32 <title>MakeStories 2.0 - Beta</title> 46 33 </head> -
makestories-helper/trunk/templates/editor-head.php
r2481763 r2516559 8 8 <script custom-element="amp-twitter" src="https://cdn.ampproject.org/v0/amp-twitter-0.1.js" async></script> 9 9 <script> 10 /*(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){10 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ 11 11 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), 12 12 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) 13 13 })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); 14 14 setTimeout(function(){ 15 if(window.isProduction){ 16 ga('create', 'UA-161794006-1', 'auto'); 17 ga('send', 'pageview'); 18 } 19 }, 1000); */ 15 ga('create', 'UA-161794006-1', 'auto'); 16 ga('set', 'appName', 'Wordpress Plugin'); 17 ga('set', 'appVersion', '<?php echo MS_PLUGIN_VERSION; ?>'); 18 ga('set', 'referrer', 'https://wordpress.makestories.io/<?php echo MS_PLUGIN_VERSION; ?>'); 19 ga('send', 'pageview'); 20 }, 2500); 20 21 </script> 21 22 <script type="text/javascript">window.$crisp = []; -
makestories-helper/trunk/templates/ms-post-by-category.php
r2481773 r2516559 1 <div class="story-thumb"> 2 <a href="<?php echo $permalink; ?>" target="_blank"> 3 <figure> 4 <img src="https://ss.makestories.io/get?story=<?php echo $storyId; ?>" /> 5 </figure> 6 </a> 7 </div> 1 <section class="default-stories"> 2 <h3><?php echo $term->name; ?></h3> 3 <div class="stories-group"> 4 <?php 5 while ($loop->have_posts()) : $loop->the_post(); 6 include mscpt_getTemplatePath("prepare-story-vars.php"); 7 include mscpt_getTemplatePath("single-story.php"); 8 endwhile; 9 wp_reset_postdata(); 10 ?> 11 </div> 12 </section>
Note: See TracChangeset
for help on using the changeset viewer.