Plugin Directory

Changeset 2516559


Ignore:
Timestamp:
04/16/2021 09:40:27 PM (5 years ago)
Author:
pressmate
Message:

Released version 2.2

Location:
makestories-helper/trunk
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • makestories-helper/trunk/api/publish.php

    r2490587 r2516559  
    3636
    3737        include_once( ABSPATH . 'wp-admin/includes/image.php' );
    38         $forceUploadMedia = ms_get_options()['forceUploadMedia'];
    3938        if( ! ( function_exists( 'wp_get_attachment_by_post_name' ) ) ) {
    4039            function wp_get_attachment_by_post_name( $post_name ) {
     
    5453            }
    5554        }
     55        $mediaLinksToDownload = [];
    5656        // Uploading media to media library of wordpress
     57        $forceUploadMedia = ms_get_options()['forceUploadMedia'];
    5758        foreach ($parsed['media'] as $media) {
    5859            $imageurl = $media['url'];
     
    8182
    8283            } 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                ];
    9989            }
    10090            if($attach_id){
     
    127117            json_encode(
    128118                getMSPostDataToSend(
    129                     get_post($post)
     119                    get_post($post),
     120                    [
     121                        "media" => $mediaLinksToDownload
     122                    ]
    130123                )
    131124            )
    132125        );
    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
     131add_action("wp_ajax_ms_upload_image_to_media_library", "ms_upload_image_to_media_library");
     132add_action("wp_ajax_nopriv_ms_upload_image_to_media_library", "ms_upload_image_to_media_library");
     133
     134function 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
    136209}
    137210
     
    284357}
    285358
    286 function getMSPostDataToSend($post){
     359function getMSPostDataToSend($post, $toReturn = []){
     360    if(!is_array($toReturn)){
     361        $toReturn = [];
     362    }
    287363    $category = [];
    288364    $terms = wp_get_post_terms($post->ID, MS_TAXONOMY);
     
    290366        $category[] = $term->name;
    291367    }
    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  
     1if (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;
    110
    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    }
    520
    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    });
    937
    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 = '';
    3840
    39   $story = '';
    40   $default = '';
     41    // Get value on form submit
     42    $('.category-allow-form').on('submit', function (e) {
     43        e.preventDefault();
    4144
    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();
    4847
    49   })
    50 })
     48    });
    5149
    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);
    5855
    59   $("#more_posts").on("click", function() {
     56    $("#more_posts").on("click", function () {
    6057
    61     // When btn is pressed.
    62     $(this).attr("disabled", true);
     58        // When btn is pressed.
     59        $(this).attr("disabled", true);
    6360
    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            });
    8482    });
    85   });
    86 });
     83})
  • makestories-helper/trunk/config.php

    r2498952 r2516559  
    11<?php
     2/**
     3 * Version of plugin in use
     4 */
     5define("MS_PLUGIN_VERSION", "2.2");
     6
    27/**
    38 * URL From where the main editor compiled files and other assets would be served
    49 */
    5 define("MS_CDN_URL", "https://api.makestories.io/wp/2.1/");
     10define("MS_CDN_URL", "https://api.makestories.io/wp/".MS_PLUGIN_VERSION."/");
    611
    712
  • makestories-helper/trunk/hooks.php

    r2481763 r2516559  
    103103    if ($post && $post->post_type == MS_POST_TYPE && is_singular(MS_POST_TYPE)) {
    104104        //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));
    106106        die();
    107107    }
     
    212212    }
    213213    else if( is_tax(MS_TAXONOMY) ) {
    214         // require(mscpt_getTemplatePath("archive-stories.php"));
    215214        $theme_files = '/taxonomy-ms_story_category.php';
    216215        if ( file_exists(get_template_directory() . $theme_files) ) {
    217216            return get_template_directory() . $theme_files;
    218217        } else {
    219             return MS_PLUGIN_BASE_PATH . '/taxonomy-ms_story_category.php';
     218            return MS_PLUGIN_BASE_PATH . $theme_files;
    220219        }
    221220    }
     
    241240    $out = '';
    242241
    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");
    252245    }
    253246   
  • makestories-helper/trunk/shortcode.php

    r2481763 r2516559  
    2121
    2222            $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;
    3027            wp_reset_postdata(); ?>
    3128        </div>
     
    4946    $cat_id = $attr['category_id'];
    5047    $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);
    5161    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'));
    7963    return ob_get_clean();
    8064}
  • makestories-helper/trunk/taxonomy-ms_story_category.php

    r2481773 r2516559  
    44$category_id = $category->term_id;
    55$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);
    620?>
    7 
    821<section class="default-stories">
    922    <h3><?php $term = get_term($int_cat,MS_TAXONOMY); echo $term->name; ?></h3>
    1023    <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        ?>
    4031    </div>
    4132</section>
  • makestories-helper/trunk/templates/archive-stories.php

    r2481773 r2516559  
    1414        $loop = new WP_Query($args);
    1515
    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;
    3020        wp_reset_postdata(); ?>
    3121    </div>
  • makestories-helper/trunk/templates/editor-full.php

    r2404028 r2516559  
    99        content="MakeStories - Web Stories Builder"
    1010    />
    11     <!--
    12       manifest.json provides metadata used when your web app is installed on a
    13       user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
    14     -->
    1511    <script async src="https://cdn.ampproject.org/v0.js"></script>
    1612    <script async custom-element="amp-facebook" src="https://cdn.ampproject.org/v0/amp-facebook-0.1.js"></script>
     
    3430    </script>
    3531    <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" will
    42       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     -->
    4532    <title>MakeStories 2.0 - Beta</title>
    4633</head>
  • makestories-helper/trunk/templates/editor-head.php

    r2481763 r2516559  
    88<script custom-element="amp-twitter" src="https://cdn.ampproject.org/v0/amp-twitter-0.1.js" async></script>
    99<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(){
    1111        (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    1212        m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    1313    })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
    1414    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);
    2021</script>
    2122<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.