We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 35549
    • 24 Posts
    Is this a problem in the web context too, or just in the other context?
    The problem occurs in the web context too. The <base/> tag is set correctly.


    //$controller = $this->modx->getOption('request_controller',null,'index.php');
    //$goToUrl = $controller . '?id=' . $postId;


    Uncommenting these lines indeed works for me (generally). However in a special case using a Babel multilingual setup I get a 404 error. I suspect this is due to the site_url not being identical to the base_url setting (e.g. site_url = http://mysite.com/de/). The resulting url redirected to is "http://mysite.com/de/index.php?id=xxx"...

    addition:
    I’m really sorry for being a bit obtrusive and I know that it’s not the topic of the original thread. But I still have questions/problems:
    - Maybe I’m really doing something wrong, but specifying a &cssfile parameter does not produce a valid css path for me. Removing "components/newspublisher/" from the following line of newspublisher.inc.php:
                   $css = $this->assetsUrl . 'components/newspublisher/css/' . $this->props['cssfile'];
    

    works if I place the custom file in "assets/components/newspublisher/css/". However wouldn’t it be better to allow specifying a complete custom path (as it is also documented in your tutorial on bobsguides.com)?

    - I have cases where a resource has no content, but is only displayed with getResources. Therefore it would be handy to have an NpEditThisButton in the getResources Tpl chunk. In this case an additional parameter would be needed do specify the ID of the resource to be edited, e.g. like this:
    [[!NpEditThisButton?id=`[[+id]]` &np_id=`1`]]

    I have a working "prototype". What do you think about this? Of course this is not compatible with the inline style of the button. Maybe the button position would have to be set using external css. Of course, it’s just an idea, which might have drawbacks (e.g. perfomance impact), and maybe I’m the only one with such a use case...

    - I made a German translation. What would be the best way to share it, if there is interest?

    Regards
      • 3749
      • 24,544 Posts
      Don’t feel bad about asking all the questions. I’d much rather have that than users who just don’t use my extras and never tell me why.

      The &css property assumes that you put the CSS file in the asset/components/newspublisher/css/ directory and supply just the name of the file in the property. That should work if you’ve done that and your assets_url is set correctly (it’s set in the core/config/config.inc.php file).

      Putting the edit button tag in the getResources Tpl chunk should work fine. You’ll get an edit button for each resource retrieved, but unless you change the CSS, they’ll all end up on top of one another at the bottom right because the default CSS positions the button absolutely. Unfortunately, I hadn’t thought of having multiple buttons on a page, so the button is positioned on the basis of the &bottom and &right properties in the tag. Your best route at this point, would probably be to change the code of the NpEditThisButton snippet to take out the absolute positioning and add your own inline CSS to put them inline with a proper left margin. If you do that, be sure to change the name of the snippet so it won’t be overwritten on upgrades (e.g., MyNpEditThisButton).

      In theory, you could create a snippet to calculate the &bottom and &right properties based on the index of the retrieved item, but I think it would probably be more trouble than it’s worth, so the other method would likely be faster and easier.

      I’d love to have a German translation (and any other translations people want to provide). smiley

      Be sure to translate both the default and properties language files -- otherwise German users will see blank descriptions when they look at the snippet properties. The files should be in utf-8 encoding and should have Unix-style line endings.

      Email me through the contact form at Bob’s Guides: http://bobsguides.com/contact-form.html and I’ll reply with an address to send the files to.



        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 35549
        • 24 Posts
        Ok, I’ll do that.

        About the &cssfile property: My assets path is correct, but this call: [[!Newspublisher?cssfile=`newspublisher.css`]] does produce the following path (which is wrong): /assets/components/newspublisher/components/newspublisher/css/newspublisher.css.
        For me it works changing this line in newspublisher.class.php (not newspublisher.inc.php, as I wrote before):
                       $css = $this->assetsUrl . 'components/newspublisher/css/' . $this->props['cssfile'];

        to
                       $css = $this->assetsUrl . 'css/' . $this->props['cssfile'];


        Hope this makes sense to you.
        Anyway, thank you for answering all my questions!
          • 35549
          • 24 Posts
          For the case that anyone has the same needs as me, here is a modified version of the NpEditThisButton snippet. It has an additional parameter for specifying the ID of the target resource to be edited (e.g. for use with getResources, allows for multiple buttons per page). There is no fixed positioning and no parameters &bottom/&right.
          example: [[!CustomEditButton?id=`5` &np_id=`2`]]

          The snippet (not thoroughly tested, but it works for me):
          <?php
          /**
           * Modified version of NpEditThisButton of the Newspublisher extra (Copyright 2011 Bob Ray), 
           * with an additional parameter for specifying the ID of the target resource to be edited 
           * (e.g. for use with getResources).
           * The button can be styled by its CSS class (np_edit_this_button)
           * example: [[!NpEditThisButton?id=`5` &np_id=`2`]]
           * 
           * @property $npId (int) - ID of newspublisher page (set automatically on first run).
           * @property $id (int) - ID of resource to be edited
           * @property $noShow - Comma-separated list of IDs of documents
           *      on which the button should not be displayed. Defaults to
           *      home page, and NewsPublisher page.
           * @property $buttonCaption (optional -- not actually a parameter) -
           *      Caption for edit button.
           *      Defaults to np_edit language string or "Edit" if empty.
           * @property $language (optional) - Language to use for error messages.
           * @property $debug (optional) - Displays the button on all pages with
           *      either the $buttonCaption, or a message explaining why it
           *      would not be shown.
           *
           */
          
          
          $language = $modx->getOption('language', $scriptProperties, null);
          $resource = empty($scriptProperties['id']) ? $modx->resource : $modx->getObject('modResource', $id);
          $language = $language ? $language . ':' : '';
          $modx->lexicon->load($language . 'newspublisher:button');
          
          /* Caption for edit button  */
          $debug = $modx->getOption('debug', $scriptProperties, false);
          $buttonCaption = $modx->lexicon('np_edit');
          $buttonCaption = empty($buttonCaption) ? 'np_edit' : $buttonCaption;
          
          /* value will be unchanged if there are no errors  */
          $value = $buttonCaption;
          
          $npId = $modx->getOption('np_id', $scriptProperties, '');
          
          /* set the np_id property to the ID of the NewsPublisher page
           * on first run if possible, error message if not */
          if (empty($npId)) {
              $npObj = $modx->getObject('modResource', array('pagetitle' => 'NewsPublisher'));
              $success = true;
              if ($npObj) {
                  $npId = $npObj->get('id');
                  $npObj = $modx->getObject('modSnippet', array('name' => 'NpEditThisButton'));
                  if ($npObj) {
                      $props = array(
                          array(
                              'name' => 'np_id',
                              'desc' => 'np_id_desc',
                              'type' => 'numberfield',
                              'options' => '',
                              'value' => $npId,
                              'lexicon' => 'newspublisher:button',
          
                          ),);
                      if ($npObj->setProperties($props, true)) {
                          $npObj->save();
                          unset($npObj);
                      } else {
                          $success = false;
                      }
          
                  } else {
                      $success = false;
                  }
              } else {
                  $success = false;
              }
              /* Failed - turn on debug to error message will display in button */
              if (!$success) {
                  $value = $modx->lexicon('np_no_np_id');
                  $debug = true;
              }
          }
          $modx->setPlaceholder('np_id', $npId);
            
            
            
          if ($resource == null) {
            $value = 'No resource of ID '.$scriptProperties['id']; 
            $id = '0';
            
          } else {
              $id = $resource->get('id');
            /* check permissions on current page */
            if (!$modx->hasPermission('edit_document')) {
                $value = $modx->lexicon('np_no_edit_document_permission');
            }
            
            if (!$modx->hasPermission('save_document')) {
                $value = $modx->lexicon('np_no_context_save_document_permission');
            }
            
            if (!$resource->checkPolicy('save')) {
                $value = $modx->lexicon('np_no_resource_save_document_permission');
            }
            /* Don't show on the the home page */
            if ($id == $modx->getOption('site_start')) {
                $value = $modx->lexicon('np_no_edit_home_page');
            }
            /* Don't show if current page is in the noShow list */
            $noShow = $modx->getOption('noShow', $scriptProperties, '');
            if (empty($noShow)) {
                $noShow = $npId . ',' . $modx->getOption('site_start');
            }
            $hidden = explode(',', $noShow);
            $hidden[] = $npId;
            if (in_array($id, $hidden)) {
                $value = 'In noShow list';
            }
          }
          /* create and return the form */
          $output = '<form action="[[~[[+np_id]]]]" method="post" class="np_button_form">';
          $output .= "\n" . '<input type = "hidden" name="np_existing" value="true" />';
          $output .= "\n" . '<input type = "hidden" name="np_doc_id" value="' . $id . '"/>';
          $output .= "\n" . '<input type="submit" class = "np_edit_this_button" name="submit" value="' . $value . '"/>';
          $output .= "\n" . '</form>';
          
          
          /* Not OK -- don't show button unless debug is on */
          if (($value != $buttonCaption) && !$debug) {
              $output = '';
          }
          
          return $output;
          
            • 3749
            • 24,544 Posts
            Thanks! I’ve added that as an option in Version 1.2.0 along with the new version of DatePicker, your other mods, and some bug fixes. I changed the name of the property to np_edit_id

            BTW, there’s no need for the getObject() call since all you need is the ID and you already have it. wink

              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 35549
              • 24 Posts
              I did the getObject() call for knowing if there is any resource with this ID and otherwise displaying an error message button if debug=`1`. But I don’t know if this is the best method. It might also have a performance impact, especially if there are multiple buttons per page...

              Anyway, I really have to thank you for helping me with getting newspublisher working on my site and for even incorporating and edit ID option in NpEditButton!!
                • 3749
                • 24,544 Posts
                Quote from: mschlegel at Jun 20, 2011, 06:24 PM

                I did the getObject() call for knowing if there is any resource with this ID and otherwise displaying an error message button if debug=`1`. But I don’t know if this is the best method. It might also have a performance impact, especially if there are multiple buttons per page...

                I see the point now. I forgot that the user might have hard-coded an ID into the tag instead of getting it via getResources (where it would be guaranteed to point to a real resource).
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 35549
                  • 24 Posts
                  I admit that this might be a very uncommon case...
                    • 3749
                    • 24,544 Posts
                    Quote from: mschlegel at Jun 22, 2011, 12:03 PM

                    I admit that this might be a very uncommon case...

                    Still, it’s a sensible sanity check and those are always good. smiley

                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting
                      • 43509
                      • 24 Posts
                      Hi!
                      I am having an issue on NewsPublisher used together with Articles (MODx Revo 2.2.6).

                      I have two context: the default one (web) and another used to translate pages in Italian (it), using Babels extras too.
                      I have two blog resources, created with Articles, each pointing to the appropriate context (web or it).

                      Now: when I use NewsPublishers to add a new article everything works great in the "web" (default) context.
                      But When I try the same in the "it" context i get an error page "503 Error - Page not found", and I noticed that MODx does not try to reach a "friendly url", but it is instead using a "http://something/it/index.php?id=269" url.
                      By the way, the resource is added both to manager and website.

                      I checked permissions, and everything seems ok on that side.

                      Do you have suggestions?
                      Thanx!