We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30884
    • 142 Posts
    I’m trying to make un-published articles viewable to web-users by making a script with takes the page id (of the article) passes it to the script, changes the published state directly by using $modx->db->update command, open it in a pop up window using javascript and then resetting the published state once it’s ran the javascript popup.

    This all works but what is not working is when i use

    $modx->sendRedirect($modx->makeUrl($manager_page_id, ’’, $start_url));

    To refresh the article manager page without the article_preview params in the url.

    When I turn on the redirect command it doesn’t execute the echo $preview_page_url.

    Any thoughts?

    Cheers

    <?php
    function preview_page($preview_id, $pub_preview_state)
    {
        global $modx;
        global $site_url;
        global $table_prefix;
        $id = isset($id) ? intval($id) : $_REQUEST[id];
        $manager_page_id = $id;
        $start_string = isset($_REQUEST[start]) ? intval($_REQUEST[start]) : 0;
        $start_url = "&start=" . $start_string;
        echo "<br>OPEN NEW WINDOW WITH ID::" . $preview_id;
        echo ":: AND PUBSTATE::" . $pub_preview_state;
        echo "<BR>";
        $content_table = $table_prefix."site_content";
        $fields = array('published'	=> 1);     
        $modx->db->update($fields, $content_table, 'id="'.$preview_id.'" ');
        
    	$javacall = "javascript:popUp('index.php?id=".$preview_id."');";
    	 $returl = "<script>".$javacall."</script>";
    	$fields = array('published'	=> 0);
    	$modx->db->update($fields, $content_table, 'id="'.$preview_id.'" ');
    	echo $returl;   
        $modx->sendRedirect($modx->makeUrl($manager_page_id, '', $start_url));
    }
    ?>
    
      p i x e l p u s h e r e x t r o d i n a i r e
      A x i s A n i m a t i o n . c o m
      • 22303 MODX Staff
      • 10,725 Posts
      That will not work; unpublished documents are not included in the site cache file, which is loaded at the beginning of each request. You would have to set the published field, recreate the entire siteCache file, reload the page and view it, then unpublish and again recreate the siteCache file. But why would you publish/unpublish for every user based on when a single-user gets a javascript popup?
        • 30884
        • 142 Posts
        Nice explanation of how that goes Jason. (soz!) Many thanks. I should elaborate a little more on what I’m up to on this.

        It’s a custom news manager which I’m working on here. The site admin here is the md and co and they’ve expressed a strong desire to keep out of the ModX backend and have a really sanitised front-end interface by which to add, edit, articles and media.

        I’m using Ditto to paginate the work articles with links to edit features underneath, content, credits, client, media, un-pub/pub. I’d like to allow them to re-view an un-published article. We’ve got publish dates tied into work articles since we’ll launch our article at the same time as publishers launch theirs etc. There is a desire to also allow others add articles but not have the permission to publish them. I felt that seeing the article in-situ would let them see how it will look in place and be able to ok it and so on.

        I’m wrangling out ways to allow these web-admin users to view an un-published article. I’m able to list them in ditto and all is good, when I rem out the redirect it works a-ok but it’s the ditto pagination navigation which preserves the url used to feed the function above that’s persisting through all the pagination navigation which is why I’ve got the page redirect/refresh in there. If there’s a way to refresh the page without any params other than Redirect I’d use that somehow. In fact I may just use HTML as opposed to the Modx api for this one.

        I’m more than happy to go back to the start on this function! (May just need to live with it for now).
        Cheers

        J

          p i x e l p u s h e r e x t r o d i n a i r e
          A x i s A n i m a t i o n . c o m