Auxiliary snippets: PHx modifiers

PubKit item management pages use a Ditto extender (pkStatus) and PHx modifiers to format the publication status flags and date fields (or suppress output if the date is not set).

For more on PHx and modifiers, see the MODx Wiki page


Ditto extender pkStatus, in file ditto/extenders/pkStatus.extender.inc.php

<?php

/*
 * Title: pkStatus
 * Purpose: set flag for PubKit list overviews
 * Use together with phx:statusFormat to format relevant column
 * Key: D = draft; P = published; W = pending pub date; X = expired;
 * fallthrough: U = unpublished (manual depublication) / Unknown
*/


# Changes
# 25 Nov 09: simplify "expired" check using unpub_date

$placeholders['status'] = array('*','status');

function status($resource) {
    if ($resource['pkPreviewFlag'] == 1) $status = 'D';
    elseif ($resource['published'] == 1) $status = 'P';
    elseif ($resource['pub_date'] > time()) $status = 'W';
    elseif (isset($resource['unpub_date']) AND $resource['unpub_date'] < time()) {
         $status = 'X';
    }
    else $status = 'U';
    return $status;
}
?>


phx:statusFormat

<?php
/**************  phx:statusFormat ********************
* formatting for table cells according to status placeholder
* (set by Ditto extender, checks preview flag, pub flag & dates)
*
* D = draft
* P = published
* W = not reached publish date yet
* X = expired
* U = unpublished manually (or Unknown)
*
* PHx options = column (flag; start, end, pub dates)
******************************************************/


$out = "";

$draft = 'pkStatusDraft';
$live = 'pkStatusLive';
$old = 'pkStatusExpired';
$fwd = 'pkStatusFwdDate';
$unpub = 'pkStatusUnpub';

switch ($options) {
    case 'flag':
        if ($output == "D") $out .= $draft;
        if ($output == "P") $out .= $live;
        if ($output == "W") $out .= $fwd;
        if ($output == "X") $out .= $old;
        if ($output == "U") $out .= $unpub;
        $out .= $flagCol;
    break;
    case 'start':
        if ($output == "D") $out .= $draft;
        if ($output == "P") $out .= $live;
        if ($output == "W") $out .= $fwd;
        if ($output == "X") $out .= $old;
        if ($output == "U") $out .= $unpub;
    break;
    case 'pub':
        if ($output == "W") $out .= $fwd;
        if ($output == "P") $out .= $live;
    break;
    case 'end':
        if ($output == "P") $out .= $live;
        if ($output == "X") $out .= $old;
    break;
}

return $out;
?>


phx:dateIfSet

<?php
// phx:dateIfSet
// format date if any, return empty string for empty date or zero

$result = NULL;

if (!empty($output) && $output > 0) {
    $result = strftime($options, $output);
}

return $result;
?>