Filter on Preview Page Url

7 posts by 3 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: May 7, 2013   (RSS)

By Djulia - April 26, 2013

Hi,

Is it possible to use a filter on Preview Page Url ?

I would like to modify the URL according to a condition.

Thanks for your assistance.

Djulia

Hi Djulia,

Could you give me a bit more detail on what you're trying to achieve? 

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By Djulia - April 26, 2013

Hi Greg,

I would like to obtain a URL different according to the value from another field for _previewUrl on action=edit.

//
function _previewUrl_modHidden($html, $tablename, $record) {
  if ($record['field'] == 1) { $previewUrl = '<input type="hidden" name="_previewUrl" id="previewUrl" value="file_one.php?preview-xxxx" />' }
  else { $previewUrl = '<input type="hidden" name="_previewUrl" id="previewUrl" value="file_two.php?preview-xxxx" />'  }  
}

Do you think that it is possible?

Thanks again!

Djulia

By Dave - May 2, 2013

Hi Djulia,

And one more approach for you, here the relevant code from /lib/menus/default/edit.php

  //
  doAction('record_preedit', $tableName, @$_REQUEST['num']);

  //
  $previewUrl = @$schema['_previewPage'] ? PREFIX_URL.@$schema['_previewPage'] : PREFIX_URL.@$schema['_detailPage'];
  if ($previewUrl) { $previewUrl .= '?' .urlencode(t('preview')). '-9999999999'; } // note that 9999999999 is a special number which getRecords() uses to know this is a preview request
  if (@$schema['_disablePreview']) { $previewUrl = ''; }

You could write a plugin that is called on 'record_preedit' that modifies $GLOBALS['schema']['_previewPage'].  Would that work for you?

Hope that helps!

Dave Edis - Senior Developer
interactivetools.com

By Dave - May 2, 2013

... that would allow you to modify the preview url based on the value of a record that is already saved.  

If you wanted to modify the preview url dynamically as the user entered different content you could do that with jQuery by adding some code to the footer on the 'admin_footer' plugin action.

Dave Edis - Senior Developer
interactivetools.com

By Djulia - May 7, 2013 - edited: May 7, 2013

My apologies for the delay.

@Dave - Your approach is perfect for me. Thanks!

addAction('record_preedit', '_custom_previewUrl_addPluginAction');

function _custom_previewUrl_addPluginAction() {
    global $schema;
    if ($schema['_tableName'] == 'my_table'
            $schema['_previewPage'] = '../';
    }
}

@Greg - Thanks for your patience!

Djulia