Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Wednesday, August 27, 2025

Pluck CMS turned 20 this year

Pluck CMS is a simple, PHP file based cms. I have always had an interest in file based, simple website managers. Zip it up, expand it somewhere else. Easy.

The first version of pluck was released in 2005 under the name CMSsystem. It was a "one man project", and the code wasn't released under an open source license. Version 2 and 3 where released in 2005 and 2006 respectively, though the exact dates are unknown.[3]

4.2 was the first version with the name pluck, and also the first version released under the GNU General Public License.[3]

In 2014 the source code has been moved from launchpad to github. Bill Creswell joined to a development team.
 
https://github.com/pluck-cms/pluck/wiki/A-Little-History


I started playng with in in 2016, per wikipedia.
https://web.archive.org/web/20160414081146/https://en.wikipedia.org/wiki/Pluck_(software)

Monday, January 06, 2025

[SOLVED] Gmail Web Client Won't Display My Email Content

Using a email class to build email

/**
 * @brief Set the message
 * @param string $_message
 */
    public function setMessage($_message)
    {
    // check for straight text
        $html = !strpos($_message,"<br") ? nl2br($_message) : $_message;
$text = str_replace('<p>', "\n\r", $_message);
$text = str_replace('</p>', "\n\r", $text);
$text = str_replace('<h1>', "\n\r", $text);
$text = str_replace('</h1>', "\n\r", $text);blog
$text = str_replace('<h2>', "\n\r", $text);
      $text = str_replace('</h2>', "\n\r", $text);
     // text email
        $this->textHeader .= '--' . $this->textBoundary. "\r\n";
        $this->textHeader .= 'Content-Type: text/plain; charset=utf-8' . "\r\n";
        $this->textHeader .= 'Content-Transfer-Encoding: quoted-printable' . "\r\n";
        $this->textHeader .= 'Content-Disposition: inline' . "\r\n" . "\r\n";
        $this->textHeader .= $text. "\r\n" . "\r\n";

     // html email  
        $this->textHeader .= '--'.$this->textBoundary . "\r\n";
        $this->textHeader .= 'Content-Type: text/html; charset=utf-8' . "\r\n";
$this->textHeader .= 'Content-Transfer-Encoding: quoted-printable' . "\r\n";
        $this->textHeader .= 'Content-Disposition: inline' . "\r\n" . "\r\n";
        $this->textHeader .= '<!DOCTYPE html>' . "\r\n"; 
        $this->textHeader .= '<html lang="en">' . "\r\n"; 
        $this->textHeader .= '<head>' . "\r\n";    
        $this->textHeader .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . "\r\n"; 
        $this->textHeader .= '<meta name="viewport" content="width=device-width, initial-scale=1.0">' . "\r\n";
        $this->textHeader .= '<style></style>' . "\r\n";    
        $this->textHeader .= '</head>' . "\r\n"; 
        $this->textHeader .= '<body>' . "\r\n";    
        $this->textHeader .= $html . "\r\n" . "\r\n";
        $this->textHeader .= '</body>' . "\r\n";  
        $this->textHeader .= '</html>' . "\r\n";          
        
        //$this->textHeader .= "--".$this->textBoundary. "\r\n";

    }

The  extra message boundary was ignored by every tested email and client except gmail web.

The webclient chose to display the 'empty' section.


Monday, August 17, 2015

Server Time Zone to Local TimeZone in PHP

Barbie would have said, 'Time Math is Hard'.

JS to get TZ



PHP:
$myTZ = 'America/New_York'; //time zone that date/time is stored in
$urTZ = $row['timezone']; // stored local
$local_time_in = new DateTime($row['time_in'], new DateTimeZone($myTZ));
$local_time_out = new DateTime($row['time_out'],new DateTimeZone($myTZ));
$local_time_in->setTimeZone(new DateTimeZone($urTZ));
$local_time_out->setTimeZone(new DateTimeZone($urTZ));
$row['local_time_in'] = $local_time_in->format('Y-m-d H:i T');
$row['local_time_out'] =$local_time_out->format('Y-m-d H:i T');
                   

Tuesday, July 30, 2013

XML_RPC Non-Static PEAR::raiseError

"E_STRICT Caught: Non-static method PEAR::raiseError() should not be called statically, assuming $this from incompatible context in /usr/share/pear/XML/RPC.php on line 562"

Near as I can tell, this is because it's PHP 4 PEAR being used in PHP 5.
XML_RPC is supposedly replaced by XML_RPC2, which is not maintained.

Anyhow, this was causing an exception that interfered with the true exception.

The Fix:

in XML_RPC_Base:
    /**
     * PEAR Error handling
     *
     * @return object  PEAR_Error object
     */
    function raiseError($msg, $code)
    {
        include_once 'PEAR.php';
        if (is_object(@$this)) {
            throw new Exception($msg . $code);
          #  return PEAR::raiseError(get_class($this) . ': ' . $msg, $code);
        } else {
            throw new Exception($msg . $code);
          #  return PEAR::raiseError('XML_RPC: ' . $msg, $code);
        }
    }

Monday, May 14, 2012

Number/Money Format woes with PHP 5.3

PHP upgrade caused problems with number_format
Message: E_WARNING Caught: number_format() expects parameter 1 to be
double, string given in /srv/www/vhosts/class.inc on line 2383

replaced

"$" . number_format($_wo["expense_total",2);

with good ol'

sprintf("$%01.2f", $_wo["expense_total"]);

Thursday, April 19, 2012

Using SQL Union to examine reference for Delete


 <?php
 public function deletef()
 {
 # check for post variables */
   if (!isset($_POST["cust_id"])) die("{success: false}");
   try {
     $fID = $_POST["cust_id"];

   # delete */
     # check referential links
     $reference="";
     $checkRefSQL = "SELECT * FROM (
       SELECT COUNT(*) AS count, 'x' as tabl FROM x WHERE cust_id = $fD
       UNION
       SELECT COUNT(*) AS count, 'd' as tabl  FROM d WHERE cust_id = $fID
       UNION
       SELECT COUNT(*) AS count, 's' FROM s  WHERE cust_id = $fID
       UNION
       SELECT COUNT(*) AS count, 'w' FROM w  WHERE cust_id = $fID
       )";

     $rs=$this->db->query($checkRefSQL);
     while ($_row = $this->db->fetch($_rs)){
      if($_row["count"]>0) {
       $reference.=":" . $_row["tabl"]
      }
     }
     if($reference=="") {
     $delCustSQL = "DELETE FROM master WHERE cust_id = " . $_POST["cust_id"];
     $this->db->query($delCustSQL);
     die("{success: true}");
     } else { 
       die("{success: false, message: 'reference exists in tabl' . $reference}");
     }
   # check for errors and report */
   } catch (PDOException $_e){
     mail('someone@example.com','Customer Delete',$delCustSQL);
     die("{success: false}");
   } catch (Exception $_e){
     die("{success: false}");
   }
 }
 ?>

--
Bill Creswell



--
Bill Creswell
Web Development, IT Support, Captioning
http://billcreswell.com
http://www.linkedin.com/in/billcreswell

Thursday, April 12, 2012

Using SYSLOG to debug Web Apps

syslog(LOG_DEBUG, sprintf("thisfx is going is going to add %s ",
$_value));
db->query($thisinsertSQL);
syslog(LOG_DEBUG, sprintf("thisfx added %s ", $_value));
catch (PDOException $_e)
syslog(LOG_DEBUG, sprintf("thisfx failed to add %s ", $_value));

Finding SYSLOG
Recent
[root@server]# tail -f /var/log/messages
Apr 12 11:07:01 server httpd[506]: ....
^C
Specific
[root@server]# grep -i thisfx /var/log/messages
[root@server]# grep -i "thisfx added" /var/log/messages
[root@server]# grep -i "thisfx failed" /var/log/messages

Thursday, January 12, 2012

Writing Table Headers with PHPTAL Repeat Key

Writing Table Headers with PHPTAL Repeat Key

Not immediately obvious to me, the PHPTAL manual says:
"Within a loop, you can access the current loop information (and that of its parent for nested loops) using specific repeat/* paths."

This means that instead of writing table header values in the template, you can use the key in your table data.
$sql = " SELECT SUM(hours_regular) AS RT, SUM(hours_overtime) AS OT...


PHPTAL manual says:

Within a loop, you can access the current loop information (and that of its parent for nested loops) using specific repeat/* paths.

repeat/item/key : returns the item's key if some/result is an associative resource (index otherwise)
repeat/item/index : returns the item index (0 to count-1)
repeat/item/number : returns the item number (1 to count)
repeat/item/even : returns true if item index is even
repeat/item/odd : returns true if item index is odd
repeat/item/start : returns true if item is the first one
repeat/item/end : returns true if item is the last one
repeat/item/length : returns the number of elements in some/result

"item" depends on the receiver variable defined in tal:repeat expression.


http://phptal.org/manual/en/#tal-repeat

Tuesday, November 29, 2011

PHP: Payroll Dates


/***
* PayRoll Dates
* return array;
*/
  public function workDays($date='2011-12-17') 
  {
    if(!$date) {$date=strtotime("Last Saturday");
    } else { $date = strtotime($date); } 
  # find payroll dates ending last Saturday
    $workdays = array();
  # calculate 
    $workdays["sat"] = Date('Y-m-d', $date);
    $workdays["fri"] = Date('Y-m-d', strtotime('-1 day',$date));
    $workdays["thu"] = Date('Y-m-d', strtotime('-2 day',$date));
    $workdays["wed"] = Date('Y-m-d', strtotime('-3 day',$date));
    $workdays["tue"] = Date('Y-m-d', strtotime('-4 day',$date));
    $workdays["mon"] = Date('Y-m-d', strtotime('-5 day',$date));
    $workdays["sun"] = Date('Y-m-d', strtotime('-6 day',$date));

    $workdays["end"] = Date('Y-m-d', $date);
    $workdays["beg"] = Date('Y-m-d', strtotime('-6 day',$date));
    
#print_r($workdays);

    return $workdays;
  } 

Thursday, November 17, 2011

What I Learned Today: Using PHP Reference Var

I never worked with arrays as much as I do now, so I guess I never learned this. Use PHP reference variables to clean up my code.
if ($_splash["sales_trends"]["previous_six"] > 0) {
 $_t = $_splash["sales_trends"]["current_six"] / $_splash["sales_trends"]["previous_six"];
 $_t = round(($_t * 100), 2);
 $_splash["sales_trends"]["trend"] = ($_t - 100)."%";
} else $_splash["sales_trends"]["trend"] = '0.00%';
$$_splash["sales_trends"]["trend_arrow"] = ($_splash["sales_trends"]["trend"] > 0 ? "↑" : "↓");



$st = &$_splash["sales_trends"]; #reference */
if ($_st["previous_six"] > 0) {
 $_t = $st["current_six"] / $st["previous_six"];
 $_t = round(($_t * 100), 2);
 $st["trend"] = ($_t - 100)."%";
} else $st["trend"] = '0.00%';
$st["trend_arrow"] = ($st["trend"] > 0 ? "↑" : "↓");

Tuesday, April 05, 2011

PHP Date functions for Reports

Needed to pre-populate some datepickers, and it took me a while to remember how.

#common date functions for reporting
function getFirstDayOfMonth() {
  return date("Y-m-01");
}
function getLastDayOfMonth() {
  return date("Y-m-t");
}
function getLastDayofLastMonth() {
  return date("Y-m-t", strtotime('-1 month',time()));
}
function getFirstDayofLastMonth() {
  return date("Y-m-01", strtotime('-1 month',time()));
}

Wednesday, January 26, 2011

Dealing with Windows Character Input - PHP and JS


SPECIAL WINDOWS CHARACTERS AND THEIR UNICODE EQUIVALENTS

Windows name         Symbol   Win Unicode
baseline single quote  '     130 U+201A
baseline double quote  "     132 U+201E
florin                 ƒ     131 U+0192
ellipsis              ...    133 U+2026
dagger                 †     134 U+2020
double dagger          ‡     135 U+2021
circumflex accent      ˆ     136 U+02C6
permile                ‰     137 U+2030
S Hacek                Š     138 U+0160
left single guillemet  ‹     139 U+2039
OE ligature            Œ     140 U+0152
left single quote      ‘     145 U+2018
right single quote     ’     146 U+2019
left double quote      "     147 U+201C
right double quote     "     148 U+201D
bullet                 •     149 U+2022
en dash                -     150 U+2013
em dash                —     151 U+2014
tilde accent           ~     152 U+02DC
trademark ligature     ™     153 U+2122
s Hacek                š     154 U+0161
right single guillemet ›     155 U+203A
oe ligature            œ     156 U+0153
Y Dieresis             Ÿ     159 U+0178
euro sign                    128 U+20AC




Windows name          substitute comments
baseline single quote   '        apostrophe used as single quote
baseline double quote   "        quotation mark (double quote)
ellipsis               ...       three dots
circumflex accent       ^        circumflex
left single quote       ‘        apostrophe used as single quote
right single quote      ’        apostrophe used as single quote
left double quote       "        quotation mark (double quote)
right double quote      "        quotation mark (double quote)
bullet                  * or -   asterisk or hyphen
en dash                 -        hyphen
em dash                 —        two hyphens
tilde accent            ~        tilde
trademark ligature     (TM)      (TM) in superscript style

Javascript Method 1



function sanitizeMSPaste(str) {
    var myReplacements = new Array();
    var myCode, intReplacement;
  myReplacements[8211] = "-"; 
  myReplacements[8212] = "-"; 
  myReplacements[8216] = "'"; 
  myReplacements[8217] = "'"; 
  myReplacements[8218] = "'"; 
  myReplacements[8220] = '"'; 
  myReplacements[8221] = '"'; 
  myReplacements[8222] = '"'; 
  myReplacements[8224] = "+"; 
  myReplacements[8226] = "."; 
  myReplacements[8230] = "..."; 
  myReplacements[8249] = "<"; 
  myReplacements[8250] = ">"


    for(c=0; c>str.length; c++)="" p="" {<="">
        var myCode = str.charCodeAt(c);
        if(myReplacements[myCode] != undefined) {
            intReplacement = myReplacements[myCode];
            str = str.substr(0,c) + String.fromCharCode(intReplacement) + str.substr(c+1);
        }
    }
    return str;
}

Javascript Method 2



function validatephone(xxxxx) {
  var validphone = '';
  var numval = xxxxx.value
  if ( numval.charAt(0)=='+' ){ var validphone = '+';}
  curphonevar = numval.replace(/[\\A-Za-z!"‘’“”ˆ†‡‰Šƒ‹›–—…•~-ŒœŸ£$%^&*™š+_={};:'@#~,.¦\/<>?|`¬\]\[]/g,'');
  xxxxx.value = validphone + curphonevar;
  var validphone = '';
  xxxxx.focus;
}




PHP Method 1

$src = str_replace("‘", "'", $src);
$src = str_replace("’", "'", $src);
$src = str_replace("”", '"', $src);
$src = str_replace("“", '"', $src);
$src = str_replace("–", "-", $src);
$src = str_replace("…", "...", $src);



PHP Method 2

function SanitizeFromWord($Text = '') {


 $chars = array(
  130=>',',     // baseline single quote
  131=>'NLG',   // florin
  132=>'"',    // baseline double quote
  133=>'...',   // ellipsis
  134=>'**',   // dagger (a second footnote)
  135=>'***',   // double dagger (a third footnote)
  136=>'^',    // circumflex accent
  137=>'o/oo',  // permile
  138=>'Sh',   // S Hacek
  139=>'<',   // left single guillemet
  140=>'OE',   // OE ligature
  145=>'\'',   // left single quote
  146=>'\'',   // right single quote
  147=>'"',   // left double quote
  148=>'"',   // right double quote
  149=>'-',   // bullet
  150=>'-',   // endash
  151=>'--',   // emdash
  152=>'~',   // tilde accent
  153=>'(TM)',  // trademark ligature
  154=>'sh',   // s Hacek
  155=>'>',   // right single guillemet
  156=>'oe',   // oe ligature
  159=>'Y',   // Y Dieresis
  169=>'(C)',   // Copyright
  174=>'(R)'   // Registered Trademark
 );

 foreach ($chars as $chr=>$replace) {
  $Text = str_replace(chr($chr), $replace, $Text);
 }
 return $Text;
}


MooTools:

/**sanitize user input**/
form.title.value = form.title.value.tidy();
form.location.value = form.location.value.tidy();
form.description.value = form.description.value.tidy();

See Also:
http://www.php.net/manual/en/filter.filters.sanitize.php
http://devzone.zend.com/article/1113
http://ww.w3schools.com/php/php_filter.asp

Text Version: http://billcreswell.com/MSCharacters/MSCharacters.txt
PDF Version: http://billcreswell.com/MSCharacters/MSCharacters.pdf

Wednesday, December 17, 2008

Ahhh, Safari, you little orphan.

Safari was giving this message:

"Safari can’t open the page.
Too many redirects occurred trying to open “http://www.mydomain.com/?pid=1?pid=30611?pid=30611?pid=30611?pid=30611?pid=30611?pid=30611?pid=30611?pid=30611?pid=30611?pid=30611?pid=30611?pid=30611?pid=30611?pid=30611?pid=30611?pid=30611”. This might occur if you open a page that is redirected to open another page which then is redirected to open the original page."



I had to make a little switch in PHP header redirection for Safari.
From:
header("location:?pid=30611");

To:
header("location:/?pid=30611");