fixed some more each() calls;
core.utils.php: added new function utils_array_kshift(); code formatting changed slightly
This commit is contained in:
parent
3ca9093f7a
commit
61ec0d9f4d
File diff suppressed because it is too large
Load Diff
@ -1,12 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
define('DRAFT_DIR', CONTENT_DIR . 'drafts/');
|
define('DRAFT_DIR', CONTENT_DIR . 'drafts/');
|
||||||
|
|
||||||
class draft_indexer extends fs_filelister {
|
class draft_indexer extends fs_filelister {
|
||||||
|
|
||||||
var $_varname = 'cache';
|
var $_varname = 'cache';
|
||||||
|
|
||||||
var $_cachefile = null;
|
var $_cachefile = null;
|
||||||
|
|
||||||
var $_directory = DRAFT_DIR;
|
var $_directory = DRAFT_DIR;
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
@ -14,9 +14,7 @@
|
|||||||
return parent::__construct();
|
return parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function _checkFile($directory, $file) {
|
function _checkFile($directory, $file) {
|
||||||
|
|
||||||
$f = "$directory/$file";
|
$f = "$directory/$file";
|
||||||
if (is_dir($f) && ctype_digit($file)) {
|
if (is_dir($f) && ctype_digit($file)) {
|
||||||
return 1;
|
return 1;
|
||||||
@ -31,7 +29,6 @@
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -39,13 +36,11 @@
|
|||||||
function &draft_init() {
|
function &draft_init() {
|
||||||
global $draftdb;
|
global $draftdb;
|
||||||
if (!isset($draftdb))
|
if (!isset($draftdb))
|
||||||
$draftdb = new draft_indexer;
|
$draftdb = new draft_indexer();
|
||||||
return $draftdb;
|
return $draftdb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function draft_getlist() {
|
function draft_getlist() {
|
||||||
|
|
||||||
static $list = array();
|
static $list = array();
|
||||||
|
|
||||||
if (!$list) {
|
if (!$list) {
|
||||||
@ -55,11 +50,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $list;
|
return $list;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function draft_parse($id) {
|
function draft_parse($id) {
|
||||||
|
|
||||||
if ($fname = draft_exists($id)) {
|
if ($fname = draft_exists($id)) {
|
||||||
|
|
||||||
$entry = io_load_file($fname);
|
$entry = io_load_file($fname);
|
||||||
@ -75,9 +68,7 @@
|
|||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function draft_save(&$entry, $id = null, $update_index = false, $update_date = false) {
|
function draft_save(&$entry, $id = null, $update_index = false, $update_date = false) {
|
||||||
|
|
||||||
if (!$id) {
|
if (!$id) {
|
||||||
$id = bdb_idfromtime('entry', $entry ['date']);
|
$id = bdb_idfromtime('entry', $entry ['date']);
|
||||||
}
|
}
|
||||||
@ -98,23 +89,22 @@
|
|||||||
$o = & entry_init();
|
$o = & entry_init();
|
||||||
$o->delete($id, null);
|
$o->delete($id, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$new_entry = entry_prepare($entry);
|
$new_entry = entry_prepare($entry);
|
||||||
if ($new_entry ['categories'])
|
if ($new_entry ['categories'])
|
||||||
$new_entry ['categories'] = implode(',', $entry ['categories']);
|
$new_entry ['categories'] = implode(',', $entry ['categories']);
|
||||||
else unset($new_entry['categories']);
|
else
|
||||||
|
unset($new_entry ['categories']);
|
||||||
|
|
||||||
$string = utils_kimplode($new_entry);
|
$string = utils_kimplode($new_entry);
|
||||||
|
|
||||||
|
|
||||||
if (!io_write_file($dd . EXT, $string)) {
|
if (!io_write_file($dd . EXT, $string)) {
|
||||||
return false;
|
return false;
|
||||||
} else return $id;
|
} else
|
||||||
|
return $id;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function draft_dir($id) {
|
function draft_dir($id) {
|
||||||
@ -124,12 +114,9 @@
|
|||||||
// $f = CONTENT_DIR . "{$date['y']}/{$date['m']}/$id";
|
// $f = CONTENT_DIR . "{$date['y']}/{$date['m']}/$id";
|
||||||
return DRAFT_DIR . $id;
|
return DRAFT_DIR . $id;
|
||||||
// return $f;
|
// return $f;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function draft_exists($id) {
|
function draft_exists($id) {
|
||||||
|
|
||||||
$dir = draft_dir($id);
|
$dir = draft_dir($id);
|
||||||
if (!$dir)
|
if (!$dir)
|
||||||
return false;
|
return false;
|
||||||
@ -156,17 +143,15 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
function draft_from_entry($entryid) {
|
* function draft_from_entry($entryid) {
|
||||||
$dir = entry_dir($entryid);
|
* $dir = entry_dir($entryid);
|
||||||
//$dir2 = str_replace('entry', 'draft', $dir);
|
* //$dir2 = str_replace('entry', 'draft', $dir);
|
||||||
$dir2 = draft_dir($entryid);
|
* $dir2 = draft_dir($entryid);
|
||||||
@rename($dir, $dir2);
|
* @rename($dir, $dir2);
|
||||||
@rename($dir.EXT, $dir2.EXT);
|
* @rename($dir.EXT, $dir2.EXT);
|
||||||
}
|
* }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function draft_to_entry($draftid) {
|
function draft_to_entry($draftid) {
|
||||||
|
|
||||||
$dir = draft_dir($draftid);
|
$dir = draft_dir($draftid);
|
||||||
$dir2 = entry_dir($draftid);
|
$dir2 = entry_dir($draftid);
|
||||||
|
|
||||||
@ -174,7 +159,6 @@
|
|||||||
draft_delete($draftid);
|
draft_delete($draftid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function smarty_block_draftlist($params, $content, &$smarty, &$repeat) {
|
function smarty_block_draftlist($params, $content, &$smarty, &$repeat) {
|
||||||
global $fpdb;
|
global $fpdb;
|
||||||
|
|
||||||
@ -182,27 +166,27 @@
|
|||||||
$smarty->assign('draft_list', $list);
|
$smarty->assign('draft_list', $list);
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function smarty_block_draft($params, $content, &$smarty, &$repeat) {
|
function smarty_block_draft($params, $content, &$smarty, &$repeat) {
|
||||||
|
|
||||||
static $list = array();
|
static $list = array();
|
||||||
|
|
||||||
$smarty->assign(array( 'subject'=>'',
|
$smarty->assign(array(
|
||||||
|
'subject' => '',
|
||||||
'content' => '',
|
'content' => '',
|
||||||
'date' => '',
|
'date' => '',
|
||||||
'author' => '',
|
'author' => '',
|
||||||
'version' => '',
|
'version' => '',
|
||||||
'id' => ''
|
'id' => ''
|
||||||
)
|
));
|
||||||
);
|
|
||||||
$arr = & $smarty->get_template_vars('draft_list');
|
$arr = & $smarty->get_template_vars('draft_list');
|
||||||
|
|
||||||
$id = $subject = null;
|
$id = $subject = null;
|
||||||
if ($arr)
|
if ($arr) {
|
||||||
list($id, $subject)=each($arr);
|
$firstElement = utils_array_kshift($arr);
|
||||||
|
$id = array_keys($firstElement) [0];
|
||||||
|
$subject = $firstElement [$id];
|
||||||
|
}
|
||||||
|
|
||||||
if ($id) {
|
if ($id) {
|
||||||
$smarty->assign('subject', $subject);
|
$smarty->assign('subject', $subject);
|
||||||
@ -214,10 +198,7 @@
|
|||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$smarty->register_block('draft_block', 'smarty_block_draftlist');
|
$smarty->register_block('draft_block', 'smarty_block_draftlist');
|
||||||
$smarty->register_block('draft', 'smarty_block_draft');
|
$smarty->register_block('draft', 'smarty_block_draft');
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class entry_cached_index extends caching_SBPT { #cache_filelister {
|
class entry_cached_index extends caching_SBPT {
|
||||||
|
// cache_filelister {
|
||||||
var $position = 0;
|
var $position = 0;
|
||||||
var $nodesize = 30;
|
|
||||||
var $keylen = 12;
|
|
||||||
|
|
||||||
|
var $nodesize = 30;
|
||||||
|
|
||||||
|
var $keylen = 12;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* opens the index belonging to a given category
|
* opens the index belonging to a given category
|
||||||
|
*
|
||||||
* @params int $id_cat
|
* @params int $id_cat
|
||||||
*/
|
*/
|
||||||
function __construct($id_cat = 0) {
|
function __construct($id_cat = 0) {
|
||||||
@ -16,17 +18,9 @@
|
|||||||
|
|
||||||
if (!file_exists($F)) {
|
if (!file_exists($F)) {
|
||||||
trigger_error("Can't find index '{$F}'", E_USER_ERROR);
|
trigger_error("Can't find index '{$F}'", E_USER_ERROR);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::__construct(
|
parent::__construct(fopen($F, 'rb'), fopen(INDEX_DIR . 'index.strings.dat', 'rb'), 256, $this->position, $this->nodesize, $this->keylen);
|
||||||
fopen($F, 'rb'),
|
|
||||||
fopen(INDEX_DIR.'index.strings.dat', 'rb'),
|
|
||||||
256,
|
|
||||||
$this->position,
|
|
||||||
$this->nodesize,
|
|
||||||
$this->keylen
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->open();
|
$this->open();
|
||||||
}
|
}
|
||||||
@ -36,13 +30,15 @@
|
|||||||
class entry_index {
|
class entry_index {
|
||||||
|
|
||||||
var $indices = array();
|
var $indices = array();
|
||||||
|
|
||||||
var $_offset = 0;
|
var $_offset = 0;
|
||||||
|
|
||||||
var $_chunksize = 30;
|
var $_chunksize = 30;
|
||||||
|
|
||||||
var $_keysize = 12;
|
var $_keysize = 12;
|
||||||
|
|
||||||
var $_lock_file = null;
|
var $_lock_file = null;
|
||||||
|
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
$this->_lock_file = CACHE_DIR . 'bpt.lock';
|
$this->_lock_file = CACHE_DIR . 'bpt.lock';
|
||||||
|
|
||||||
@ -66,28 +62,17 @@
|
|||||||
else
|
else
|
||||||
$mode = 'w+b';
|
$mode = 'w+b';
|
||||||
|
|
||||||
$this->indices[0] = new SBPlusTree(
|
$this->indices [0] = new SBPlusTree(fopen($f, $mode), fopen(INDEX_DIR . 'index.strings.dat', $mode), 256, $this->_offset, $this->_chunksize, $this->_keysize);
|
||||||
fopen($f, $mode),
|
|
||||||
fopen(INDEX_DIR.'index.strings.dat', $mode),
|
|
||||||
256,
|
|
||||||
$this->_offset,
|
|
||||||
$this->_chunksize,
|
|
||||||
$this->_keysize
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($oldfile)
|
if ($oldfile)
|
||||||
$this->indices [0]->open();
|
$this->indices [0]->open();
|
||||||
else
|
else
|
||||||
$this->indices [0]->startup();
|
$this->indices [0]->startup();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _lock_acquire($exclusive = true, $cat = 0) {
|
function _lock_acquire($exclusive = true, $cat = 0) {
|
||||||
if (file_exists($this->_lock_file)) {
|
if (file_exists($this->_lock_file)) {
|
||||||
trigger_error("Could not acquire write lock on INDEX. ".
|
trigger_error("Could not acquire write lock on INDEX. " . "Didn't I told you FlatPress is not designed for concurrency, already? ;) " . "Don't worry: your entry has been saved as draft!", E_USER_WARNING);
|
||||||
"Didn't I told you FlatPress is not designed for concurrency, already? ;) ".
|
|
||||||
"Don't worry: your entry has been saved as draft!", E_USER_WARNING);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +85,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _lock_release($cat = 0) {
|
function _lock_release($cat = 0) {
|
||||||
@ -110,7 +94,6 @@
|
|||||||
trigger_error("Lock file did not exist: ignoring (index was already unlocked.)", E_USER_NOTICE);
|
trigger_error("Lock file did not exist: ignoring (index was already unlocked.)", E_USER_NOTICE);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function &get_index($cat = 0) {
|
function &get_index($cat = 0) {
|
||||||
@ -120,17 +103,14 @@
|
|||||||
$f = INDEX_DIR . 'index-' . $cat . '.dat';
|
$f = INDEX_DIR . 'index-' . $cat . '.dat';
|
||||||
if ($oldfile = file_exists($f))
|
if ($oldfile = file_exists($f))
|
||||||
$mode = 'r+b';
|
$mode = 'r+b';
|
||||||
else $mode = 'w+b';
|
else
|
||||||
|
$mode = 'w+b';
|
||||||
|
|
||||||
$this->indices[$cat] = new BPlusTree(
|
$this->indices [$cat] = new BPlusTree(fopen($f, $mode), $this->_offset, $this->_chunksize, $this->_keysize);
|
||||||
fopen($f, $mode),
|
|
||||||
$this->_offset,
|
|
||||||
$this->_chunksize,
|
|
||||||
$this->_keysize
|
|
||||||
);
|
|
||||||
if ($oldfile)
|
if ($oldfile)
|
||||||
$this->indices [$cat]->open();
|
$this->indices [$cat]->open();
|
||||||
else $this->indices[$cat]->startup();
|
else
|
||||||
|
$this->indices [$cat]->startup();
|
||||||
}
|
}
|
||||||
return $this->indices [$cat];
|
return $this->indices [$cat];
|
||||||
}
|
}
|
||||||
@ -139,7 +119,8 @@
|
|||||||
$key = entry_idtokey($id);
|
$key = entry_idtokey($id);
|
||||||
$val = $entry ['subject'];
|
$val = $entry ['subject'];
|
||||||
|
|
||||||
if (!$this->_lock_acquire()) return false; // we're DOOMED!
|
if (!$this->_lock_acquire())
|
||||||
|
return false; // we're DOOMED!
|
||||||
|
|
||||||
$main = & $this->get_index();
|
$main = & $this->get_index();
|
||||||
$seek = null;
|
$seek = null;
|
||||||
@ -163,7 +144,8 @@
|
|||||||
foreach ($entry ['categories'] as $cat) {
|
foreach ($entry ['categories'] as $cat) {
|
||||||
|
|
||||||
// skip non-numeric special categories (such as 'draft')
|
// skip non-numeric special categories (such as 'draft')
|
||||||
if (!is_numeric($cat)) continue;
|
if (!is_numeric($cat))
|
||||||
|
continue;
|
||||||
|
|
||||||
$categories [] = $cat;
|
$categories [] = $cat;
|
||||||
|
|
||||||
@ -189,28 +171,29 @@
|
|||||||
if ($del) {
|
if ($del) {
|
||||||
foreach ($del as $cat) {
|
foreach ($del as $cat) {
|
||||||
// echo 'DEL '. $cat,"\n";
|
// echo 'DEL '. $cat,"\n";
|
||||||
if (!is_numeric($cat)) continue;
|
if (!is_numeric($cat))
|
||||||
|
continue;
|
||||||
$this_index = & $this->get_index($cat);
|
$this_index = & $this->get_index($cat);
|
||||||
$this_index->delitem($key);
|
$this_index->delitem($key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->_lock_release();
|
return $this->_lock_release();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete($id, $entry) {
|
function delete($id, $entry) {
|
||||||
$key = entry_idtokey($id);
|
$key = entry_idtokey($id);
|
||||||
|
|
||||||
if (!$this->_lock_acquire()) return false; // we're DOOMED!
|
if (!$this->_lock_acquire())
|
||||||
|
return false; // we're DOOMED!
|
||||||
|
|
||||||
$main = & $this->get_index();
|
$main = & $this->get_index();
|
||||||
$main->delitem($key);
|
$main->delitem($key);
|
||||||
|
|
||||||
|
|
||||||
if (isset($entry ['categories']) && is_array($entry ['categories'])) {
|
if (isset($entry ['categories']) && is_array($entry ['categories'])) {
|
||||||
foreach ($entry ['categories'] as $cat) {
|
foreach ($entry ['categories'] as $cat) {
|
||||||
if (!is_numeric($cat)) continue;
|
if (!is_numeric($cat))
|
||||||
|
continue;
|
||||||
$this_index = & $this->get_index($cat);
|
$this_index = & $this->get_index($cat);
|
||||||
if ($this_index->has_key($key))
|
if ($this_index->has_key($key))
|
||||||
$this_index->delitem($key);
|
$this_index->delitem($key);
|
||||||
@ -218,7 +201,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $this->_lock_release();
|
return $this->_lock_release();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -226,8 +208,11 @@
|
|||||||
class entry_archives extends fs_filelister {
|
class entry_archives extends fs_filelister {
|
||||||
|
|
||||||
var $_directory = CONTENT_DIR;
|
var $_directory = CONTENT_DIR;
|
||||||
|
|
||||||
var $_y = null;
|
var $_y = null;
|
||||||
|
|
||||||
var $_m = null;
|
var $_m = null;
|
||||||
|
|
||||||
var $_d = null;
|
var $_d = null;
|
||||||
|
|
||||||
var $_count = 0;
|
var $_count = 0;
|
||||||
@ -235,7 +220,6 @@
|
|||||||
var $_filter = 'entry*';
|
var $_filter = 'entry*';
|
||||||
|
|
||||||
function __construct($y, $m = null, $d = null) {
|
function __construct($y, $m = null, $d = null) {
|
||||||
|
|
||||||
$this->_y = $y;
|
$this->_y = $y;
|
||||||
$this->_m = $m;
|
$this->_m = $m;
|
||||||
$this->_d = $d;
|
$this->_d = $d;
|
||||||
@ -249,7 +233,6 @@
|
|||||||
if ($d) {
|
if ($d) {
|
||||||
$this->_filter = "entry$y$m$d*";
|
$this->_filter = "entry$y$m$d*";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::__construct();
|
return parent::__construct();
|
||||||
@ -280,44 +263,42 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* //work in progress
|
// //work in progress
|
||||||
class entry {
|
// class entry {
|
||||||
|
|
||||||
var $_indexer;
|
// var $_indexer;
|
||||||
var $id;
|
// var $id;
|
||||||
|
|
||||||
function entry($id, $content) {
|
// function entry($id, $content) {
|
||||||
//$this->_indexer =& $indexer;
|
// //$this->_indexer =& $indexer;
|
||||||
}
|
// }
|
||||||
|
|
||||||
function get($field) {
|
// function get($field) {
|
||||||
$field = strtolower($field);
|
// $field = strtolower($field);
|
||||||
if (!isset($this->$field)) {
|
// if (!isset($this->$field)) {
|
||||||
// if it is not set
|
// // if it is not set
|
||||||
// tries to fetch from the database
|
// // tries to fetch from the database
|
||||||
$arr = entry_parse($id);
|
// $arr = entry_parse($id);
|
||||||
while(list($field, $val) = each($arr))
|
// while(list($field, $val) = each($arr))
|
||||||
$this->$field = $val;
|
// $this->$field = $val;
|
||||||
|
|
||||||
// if still is not set raises an error
|
// // if still is not set raises an error
|
||||||
if (!isset($this->$field))
|
// if (!isset($this->$field))
|
||||||
trigger_error("$field is not set", E_USER_NOTICE);
|
// trigger_error("$field is not set", E_USER_NOTICE);
|
||||||
return;
|
// return;
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
// return $this->$field;
|
||||||
|
|
||||||
return $this->$field;
|
// }
|
||||||
|
|
||||||
}
|
// function set($field, $val) {
|
||||||
|
// $field = strtolower($field);
|
||||||
|
// $this->$field = $val;
|
||||||
|
// }
|
||||||
|
|
||||||
function set($field, $val) {
|
// }
|
||||||
$field = strtolower($field);
|
|
||||||
$this->$field = $val;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* function entry_init
|
* function entry_init
|
||||||
@ -325,20 +306,17 @@
|
|||||||
*/
|
*/
|
||||||
function &entry_init() {
|
function &entry_init() {
|
||||||
|
|
||||||
#global $fpdb;
|
// global $fpdb;
|
||||||
#$fpdb->init();
|
// $fpdb->init();
|
||||||
|
|
||||||
static $entry_index = null;
|
static $entry_index = null;
|
||||||
|
|
||||||
if (is_null($entry_index))
|
if (is_null($entry_index))
|
||||||
$entry_index= new entry_index;
|
$entry_index = new entry_index();
|
||||||
|
|
||||||
return $entry_index;
|
return $entry_index;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function &entry_cached_index($id_cat) {
|
function &entry_cached_index($id_cat) {
|
||||||
|
|
||||||
$F = INDEX_DIR . 'index-' . $id_cat . '.dat';
|
$F = INDEX_DIR . 'index-' . $id_cat . '.dat';
|
||||||
|
|
||||||
if (!file_exists($F)) {
|
if (!file_exists($F)) {
|
||||||
@ -348,31 +326,28 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $o;
|
return $o;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
function entry_query($params=array()){
|
* function entry_query($params=array()){
|
||||||
|
*
|
||||||
global $fpdb;
|
* global $fpdb;
|
||||||
$queryid = $fpdb->query($params);
|
* $queryid = $fpdb->query($params);
|
||||||
$fpdb->doquery($queryid);
|
* $fpdb->doquery($queryid);
|
||||||
|
*
|
||||||
|
*
|
||||||
}
|
* }
|
||||||
|
*
|
||||||
function entry_hasmore() {
|
* function entry_hasmore() {
|
||||||
global $fpdb;
|
* global $fpdb;
|
||||||
return $fpdb->hasmore();
|
* return $fpdb->hasmore();
|
||||||
|
*
|
||||||
}
|
* }
|
||||||
|
*
|
||||||
function entry_get() {
|
* function entry_get() {
|
||||||
$fpdb->get();
|
* $fpdb->get();
|
||||||
}
|
* }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function entry_keytoid($key) {
|
function entry_keytoid($key) {
|
||||||
$date = substr($key, 0, 6);
|
$date = substr($key, 0, 6);
|
||||||
$time = substr($key, 6);
|
$time = substr($key, 6);
|
||||||
@ -396,8 +371,7 @@
|
|||||||
$arr ['M'] = substr($key, 8, 2);
|
$arr ['M'] = substr($key, 8, 2);
|
||||||
$arr ['S'] = substr($key, 10, 2);
|
$arr ['S'] = substr($key, 10, 2);
|
||||||
|
|
||||||
return mktime($arr['H'], $arr['M'], $arr['S'],
|
return mktime($arr ['H'], $arr ['M'], $arr ['S'], $arr ['m'], $arr ['d'], $arr ['y']);
|
||||||
$arr['m'], $arr['d'], $arr['y']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function entry_idtotime($id) {
|
function entry_idtotime($id) {
|
||||||
@ -406,14 +380,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function entry_list() {
|
function entry_list() {
|
||||||
|
|
||||||
trigger_error('function deprecated', E_USER_ERROR);
|
trigger_error('function deprecated', E_USER_ERROR);
|
||||||
|
|
||||||
$obj = & entry_init();
|
$obj = & entry_init();
|
||||||
|
|
||||||
$entry_arr = $obj->getList();
|
$entry_arr = $obj->getList();
|
||||||
|
|
||||||
|
|
||||||
if ($entry_arr) {
|
if ($entry_arr) {
|
||||||
krsort($entry_arr);
|
krsort($entry_arr);
|
||||||
return $entry_arr;
|
return $entry_arr;
|
||||||
@ -434,12 +406,9 @@
|
|||||||
else
|
else
|
||||||
$f = CONTENT_DIR . "{$date['y']}/{$date['m']}/$id";
|
$f = CONTENT_DIR . "{$date['y']}/{$date['m']}/$id";
|
||||||
return $f;
|
return $f;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function entry_parse($id, $raw = false) {
|
function entry_parse($id, $raw = false) {
|
||||||
|
|
||||||
$f = entry_exists($id);
|
$f = entry_exists($id);
|
||||||
if (!$f)
|
if (!$f)
|
||||||
return array();
|
return array();
|
||||||
@ -453,17 +422,13 @@
|
|||||||
|
|
||||||
// propagates the error if entry does not exist
|
// propagates the error if entry does not exist
|
||||||
|
|
||||||
|
|
||||||
if (isset($arr ['categories']) && // fix to bad old behaviour:
|
if (isset($arr ['categories']) && // fix to bad old behaviour:
|
||||||
(trim($arr ['categories']) != '')) {
|
(trim($arr ['categories']) != '')) {
|
||||||
|
|
||||||
|
|
||||||
$cats = (array) explode(',', $arr ['categories']);
|
$cats = (array) explode(',', $arr ['categories']);
|
||||||
$arr ['categories'] = (array) $cats;
|
$arr ['categories'] = (array) $cats;
|
||||||
|
} else
|
||||||
|
$arr ['categories'] = array();
|
||||||
|
|
||||||
} else $arr['categories'] = array();
|
|
||||||
|
|
||||||
// if (!is_array($arr['categories'])) die();
|
// if (!is_array($arr['categories'])) die();
|
||||||
|
|
||||||
@ -472,35 +437,32 @@
|
|||||||
$arr ['AUTHOR'] = $fp_config ['general'] ['author'];
|
$arr ['AUTHOR'] = $fp_config ['general'] ['author'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($raw) return $arr;
|
if ($raw)
|
||||||
|
return $arr;
|
||||||
return $arr;
|
return $arr;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* function entry_get_comments
|
* function entry_get_comments
|
||||||
*
|
*
|
||||||
* @param string id entry id
|
* @param
|
||||||
* @param array entry entry content array by ref; 'commentcount' field is added to the array
|
* string id entry id
|
||||||
|
* @param
|
||||||
|
* array entry entry content array by ref; 'commentcount' field is added to the array
|
||||||
*
|
*
|
||||||
* @return object comment_indexer as reference
|
* @return object comment_indexer as reference
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function &entry_get_comments($id, &$count) {
|
function &entry_get_comments($id, &$count) {
|
||||||
$obj = new comment_indexer($id);
|
$obj = new comment_indexer($id);
|
||||||
|
|
||||||
$count = count($obj->getList());
|
$count = count($obj->getList());
|
||||||
|
|
||||||
return $obj;
|
return $obj;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function entry_categories_encode($cat_file) {
|
function entry_categories_encode($cat_file) {
|
||||||
|
|
||||||
|
|
||||||
// if ($string = io_load_file(CONTENT_DIR . 'categories.txt')) {
|
// if ($string = io_load_file(CONTENT_DIR . 'categories.txt')) {
|
||||||
$lines = explode("\n", trim($cat_file));
|
$lines = explode("\n", trim($cat_file));
|
||||||
$idstack = $result = $indentstack = array();
|
$idstack = $result = $indentstack = array();
|
||||||
@ -523,9 +485,8 @@
|
|||||||
|
|
||||||
// IDs must be strictly positive
|
// IDs must be strictly positive
|
||||||
|
|
||||||
if ($label && $id <= 0) return -1;
|
if ($label && $id <= 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
|
||||||
if (empty($indentstack)) {
|
if (empty($indentstack)) {
|
||||||
array_push($indentstack, $indent);
|
array_push($indentstack, $indent);
|
||||||
@ -539,19 +500,22 @@
|
|||||||
array_push($indentstack, $indent);
|
array_push($indentstack, $indent);
|
||||||
array_push($idstack, $id);
|
array_push($idstack, $id);
|
||||||
} elseif ($indent > $indent_old) {
|
} elseif ($indent > $indent_old) {
|
||||||
$idstack = array($id);
|
$idstack = array(
|
||||||
$indentstack = array($indent);
|
$id
|
||||||
|
);
|
||||||
|
$indentstack = array(
|
||||||
|
$indent
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
array_pop($idstack);
|
array_pop($idstack);
|
||||||
$idstack = array($id);
|
$idstack = array(
|
||||||
|
$id
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$result ['rels'] [$id] = $idstack;
|
$result ['rels'] [$id] = $idstack;
|
||||||
$result ['defs'] [$id] = $label;
|
$result ['defs'] [$id] = $label;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ksort($result ['rels']);
|
ksort($result ['rels']);
|
||||||
@ -564,27 +528,26 @@
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
*
|
||||||
function entry_categories_print(&$lines, &$indentstack, &$result, $params) {
|
* function entry_categories_print(&$lines, &$indentstack, &$result, $params) {
|
||||||
|
*
|
||||||
|
*
|
||||||
}
|
* }
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
function entry_categories_list() {
|
function entry_categories_list() {
|
||||||
if (!$string = io_load_file(CONTENT_DIR . 'categories.txt'))
|
if (!$string = io_load_file(CONTENT_DIR . 'categories.txt'))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
$lines = explode("\n", trim($string));
|
$lines = explode("\n", trim($string));
|
||||||
$idstack = array(0);
|
$idstack = array(
|
||||||
|
0
|
||||||
|
);
|
||||||
$indentstack = array();
|
$indentstack = array();
|
||||||
|
|
||||||
|
|
||||||
// $categories = array(0=>null);
|
// $categories = array(0=>null);
|
||||||
$lastindent = 0;
|
$lastindent = 0;
|
||||||
$lastid = 0;
|
$lastid = 0;
|
||||||
@ -596,7 +559,8 @@
|
|||||||
|
|
||||||
$vt = trim($v);
|
$vt = trim($v);
|
||||||
|
|
||||||
if (!$vt) continue;
|
if (!$vt)
|
||||||
|
continue;
|
||||||
|
|
||||||
$text = '';
|
$text = '';
|
||||||
$indent = utils_countdashes($vt, $text);
|
$indent = utils_countdashes($vt, $text);
|
||||||
@ -621,7 +585,8 @@
|
|||||||
array_pop($idstack);
|
array_pop($idstack);
|
||||||
$NEST--;
|
$NEST--;
|
||||||
} while ($dedent > $indent);
|
} while ($dedent > $indent);
|
||||||
if ($dedent < $indent) return false; //trigger_error("failed parsing ($dedent<$indent)", E_USER_ERROR);
|
if ($dedent < $indent)
|
||||||
|
return false; // trigger_error("failed parsing ($dedent<$indent)", E_USER_ERROR);
|
||||||
$parent = end($idstack);
|
$parent = end($idstack);
|
||||||
$lastindent = $indent;
|
$lastindent = $indent;
|
||||||
$lastid = $id;
|
$lastid = $id;
|
||||||
@ -630,17 +595,13 @@
|
|||||||
$lastid = $id;
|
$lastid = $id;
|
||||||
// echo "NEST: $NEST\n";
|
// echo "NEST: $NEST\n";
|
||||||
|
|
||||||
|
|
||||||
$categories [$id] = $parent;
|
$categories [$id] = $parent;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $categories;
|
return $categories;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function entry_categories_get($what = null) {
|
function entry_categories_get($what = null) {
|
||||||
|
|
||||||
global $fpdb;
|
global $fpdb;
|
||||||
|
|
||||||
$categories = array();
|
$categories = array();
|
||||||
@ -654,7 +615,6 @@
|
|||||||
if ($c = io_load_file($f))
|
if ($c = io_load_file($f))
|
||||||
$categories = unserialize($c);
|
$categories = unserialize($c);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($categories) {
|
if ($categories) {
|
||||||
@ -668,30 +628,23 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* flags are actually special categories
|
||||||
flags are actually special categories
|
* which are usually hidden.
|
||||||
which are usually hidden.
|
*
|
||||||
|
* they can be set when editing your entries
|
||||||
they can be set when editing your entries
|
* to let flatpress perform special actions
|
||||||
to let flatpress perform special actions
|
*
|
||||||
|
* draft: Draft entry (hidden, awaiting publication)
|
||||||
draft: Draft entry (hidden, awaiting publication)
|
* static: Static entry (allows saving an alias, so you can reach it with
|
||||||
static: Static entry (allows saving an alias, so you can reach it with
|
* ?page=myentry)
|
||||||
?page=myentry)
|
* commslock: Comments locked (comments disallowed for this entry)
|
||||||
commslock: Comments locked (comments disallowed for this entry)
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function entry_flags_get() {
|
function entry_flags_get() {
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'draft',
|
'draft',
|
||||||
// 'static',
|
// 'static',
|
||||||
'commslock'
|
'commslock'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @TODO : check against schema ?
|
// @TODO : check against schema ?
|
||||||
@ -710,30 +663,30 @@
|
|||||||
$entry ['content'] = apply_filters('content_save_pre', $entry ['content']);
|
$entry ['content'] = apply_filters('content_save_pre', $entry ['content']);
|
||||||
$entry ['subject'] = apply_filters('title_save_pre', $entry ['subject']);
|
$entry ['subject'] = apply_filters('title_save_pre', $entry ['subject']);
|
||||||
|
|
||||||
|
|
||||||
// prepare for serialization
|
// prepare for serialization
|
||||||
if (isset($entry ['categories'])) {
|
if (isset($entry ['categories'])) {
|
||||||
|
|
||||||
if (!is_array($entry ['categories'])) {
|
if (!is_array($entry ['categories'])) {
|
||||||
trigger_error("Expected 'categories' to be an array, found "
|
trigger_error("Expected 'categories' to be an array, found " . gettype($entry ['categories']), E_USER_WARNING);
|
||||||
. gettype($entry['categories']), E_USER_WARNING);
|
$entry ['categories'] = array();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
$entry ['categories'] = array();
|
$entry ['categories'] = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
} else { $entry['categories'] = array(); }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return $entry;
|
return $entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param array entry contents
|
* @param
|
||||||
* @param string|null entry id, null if can be deducted from the date field of $entry;
|
* array entry contents
|
||||||
|
* @param
|
||||||
|
* string|null entry id, null if can be deducted from the date field of $entry;
|
||||||
* defaults to null
|
* defaults to null
|
||||||
*
|
*
|
||||||
* @param bool updates entry index; defaults to true
|
* @param
|
||||||
|
* bool updates entry index; defaults to true
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @return integer -1 failure while storing preliminar draft, abort. Index not touched.
|
* @return integer -1 failure while storing preliminar draft, abort. Index not touched.
|
||||||
@ -746,16 +699,15 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function entry_save($entry, $id = null, $update_index = true) {
|
function entry_save($entry, $id = null, $update_index = true) {
|
||||||
|
|
||||||
// PHASE 1 : prepare entry
|
// PHASE 1 : prepare entry
|
||||||
if (!$id) {
|
if (!$id) {
|
||||||
if (!@$entry['date']) $entry['date'] = date_time();
|
if (!@$entry ['date'])
|
||||||
|
$entry ['date'] = date_time();
|
||||||
$id = bdb_idfromtime(BDB_ENTRY, $entry ['date']);
|
$id = bdb_idfromtime(BDB_ENTRY, $entry ['date']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// PHASE 2 : Store
|
// PHASE 2 : Store
|
||||||
|
|
||||||
// secure data as DRAFT
|
// secure data as DRAFT
|
||||||
@ -767,7 +719,6 @@
|
|||||||
return -1; // FAILURE: ABORT
|
return -1; // FAILURE: ABORT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// PHASE 3 : Update index
|
// PHASE 3 : Update index
|
||||||
$delete_cats = array();
|
$delete_cats = array();
|
||||||
$all_cats = @$entry ['categories'];
|
$all_cats = @$entry ['categories'];
|
||||||
@ -781,14 +732,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
echo 'old';
|
* echo 'old';
|
||||||
print_r($old_entry['categories']);
|
* print_r($old_entry['categories']);
|
||||||
echo 'new';
|
* echo 'new';
|
||||||
print_r($entry['categories']);
|
* print_r($entry['categories']);
|
||||||
echo 'del';
|
* echo 'del';
|
||||||
print_r($delete_cats);
|
* print_r($delete_cats);
|
||||||
echo 'all';
|
* echo 'all';
|
||||||
print_r($all_cats);
|
* print_r($all_cats);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$INDEX = & entry_init();
|
$INDEX = & entry_init();
|
||||||
@ -827,29 +778,24 @@
|
|||||||
draft_to_entry($id);
|
draft_to_entry($id);
|
||||||
return $id;
|
return $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return -4;
|
return -4;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function entry_delete($id) {
|
function entry_delete($id) {
|
||||||
|
|
||||||
if (!$f = entry_exists($id))
|
if (!$f = entry_exists($id))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
$d = bdb_idtofile($id,BDB_COMMENT);
|
* $d = bdb_idtofile($id,BDB_COMMENT);
|
||||||
fs_delete_recursive("$d");
|
* fs_delete_recursive("$d");
|
||||||
|
*
|
||||||
// thanks to cimangi for noticing this
|
* // thanks to cimangi for noticing this
|
||||||
$f = dirname($d) . '/view_counter' .EXT;
|
* $f = dirname($d) . '/view_counter' .EXT;
|
||||||
fs_delete($f);
|
* fs_delete($f);
|
||||||
|
*
|
||||||
|
*
|
||||||
$f = bdb_idtofile($id);
|
* $f = bdb_idtofile($id);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$d = entry_dir($id);
|
$d = entry_dir($id);
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
// utils.php
|
// utils.php
|
||||||
// library of misc utilities
|
// library of misc utilities
|
||||||
|
|
||||||
|
|
||||||
// function subkey sort
|
// function subkey sort
|
||||||
// function prototype :
|
// function prototype :
|
||||||
// array utils_sksort(array $arr, string $key, int $flag=SORT_ASC)
|
// array utils_sksort(array $arr, string $key, int $flag=SORT_ASC)
|
||||||
@ -17,7 +16,8 @@
|
|||||||
$sorter [] = $val [$key];
|
$sorter [] = $val [$key];
|
||||||
array_multisort($sorter, $flag, $arr);
|
array_multisort($sorter, $flag, $arr);
|
||||||
return $arr;
|
return $arr;
|
||||||
} else return false;
|
} else
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// function prototype:
|
// function prototype:
|
||||||
@ -39,29 +39,39 @@
|
|||||||
// as usual, slightly modified to fit my tastes :)
|
// as usual, slightly modified to fit my tastes :)
|
||||||
|
|
||||||
if (!function_exists('fnmatch')) {
|
if (!function_exists('fnmatch')) {
|
||||||
function fnmatch($pattern, $string) {
|
|
||||||
|
|
||||||
|
function fnmatch($pattern, $string) {
|
||||||
if ($pattern == null)
|
if ($pattern == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// basically prepare a regular expression
|
// basically prepare a regular expression
|
||||||
$out = null;
|
$out = null;
|
||||||
$chunks = explode(';', $pattern);
|
$chunks = explode(';', $pattern);
|
||||||
foreach($chunks as $pattern)
|
foreach ($chunks as $pattern) {
|
||||||
{
|
$escape = array(
|
||||||
$escape=array('$','^','.','{','}','(',')','[',']','|');
|
'$',
|
||||||
|
'^',
|
||||||
|
'.',
|
||||||
|
'{',
|
||||||
|
'}',
|
||||||
|
'(',
|
||||||
|
')',
|
||||||
|
'[',
|
||||||
|
']',
|
||||||
|
'|'
|
||||||
|
);
|
||||||
while (strpos($pattern, '**') !== false)
|
while (strpos($pattern, '**') !== false)
|
||||||
$pattern = str_replace('**', '*', $pattern);
|
$pattern = str_replace('**', '*', $pattern);
|
||||||
|
|
||||||
foreach ($escape as $probe)
|
foreach ($escape as $probe)
|
||||||
$pattern = str_replace($probe, "\\$probe", $pattern);
|
$pattern = str_replace($probe, "\\$probe", $pattern);
|
||||||
$pattern=str_replace('?*','*', str_replace('*?','*',
|
$pattern = str_replace('?*', '*', str_replace('*?', '*', str_replace('*', ".*", str_replace('?', '.{1,1}', $pattern))));
|
||||||
str_replace('*',".*",
|
|
||||||
str_replace('?','.{1,1}',$pattern))));
|
|
||||||
$out [] = $pattern;
|
$out [] = $pattern;
|
||||||
}
|
}
|
||||||
/* // NoWhereMan note: why splitting this in two? :)
|
/*
|
||||||
if(count($out)==1) return(eregi("^$out[0]$",$string)); else*/
|
* // NoWhereMan note: why splitting this in two? :)
|
||||||
|
* if(count($out)==1) return(eregi("^$out[0]$",$string)); else
|
||||||
|
*/
|
||||||
foreach ($out as $tester) {
|
foreach ($out as $tester) {
|
||||||
if (preg_match("/^$tester$/i", $string))
|
if (preg_match("/^$tester$/i", $string))
|
||||||
return true;
|
return true;
|
||||||
@ -71,7 +81,6 @@ if (!function_exists('fnmatch')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// function prototype:
|
// function prototype:
|
||||||
// array utils_kexplode(string $string, string $delim='|')
|
// array utils_kexplode(string $string, string $delim='|')
|
||||||
|
|
||||||
@ -81,7 +90,6 @@ if (!function_exists('fnmatch')) {
|
|||||||
// key1|value1|key2|value2 , etc.
|
// key1|value1|key2|value2 , etc.
|
||||||
// the array will look like
|
// the array will look like
|
||||||
// $arr['key1'] = 'value1'; $arr['key2'] = 'value2'; etc.
|
// $arr['key1'] = 'value1'; $arr['key2'] = 'value2'; etc.
|
||||||
|
|
||||||
function utils_kexplode($string, $delim = '|', $keyupper = true) {
|
function utils_kexplode($string, $delim = '|', $keyupper = true) {
|
||||||
$arr = array();
|
$arr = array();
|
||||||
$string = trim($string);
|
$string = trim($string);
|
||||||
@ -91,12 +99,12 @@ if (!function_exists('fnmatch')) {
|
|||||||
while (($k = strtok($delim)) !== false) {
|
while (($k = strtok($delim)) !== false) {
|
||||||
if ($keyupper && !preg_match('/[A-Z-_]/', $k)) {
|
if ($keyupper && !preg_match('/[A-Z-_]/', $k)) {
|
||||||
/*
|
/*
|
||||||
trigger_error("Failed parsing <pre>$string</pre>
|
* trigger_error("Failed parsing <pre>$string</pre>
|
||||||
keys were supposed to be UPPERCASE but <strong>\"$k\"</strong> was found; file may be corrupted
|
* keys were supposed to be UPPERCASE but <strong>\"$k\"</strong> was found; file may be corrupted
|
||||||
or in an expected format. <br />
|
* or in an expected format. <br />
|
||||||
Some SimplePHPBlog files may raise this error: set DUMB_MODE_ENABLED
|
* Some SimplePHPBlog files may raise this error: set DUMB_MODE_ENABLED
|
||||||
to true in your defaults.php to force parsing of the offending keys.",
|
* to true in your defaults.php to force parsing of the offending keys.",
|
||||||
E_USER_WARNING);
|
* E_USER_WARNING);
|
||||||
*/
|
*/
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -107,44 +115,43 @@ if (!function_exists('fnmatch')) {
|
|||||||
return $arr;
|
return $arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
function utils_newkexplode($string, $delim='|') {
|
* function utils_newkexplode($string, $delim='|') {
|
||||||
|
*
|
||||||
$arr = array();
|
* $arr = array();
|
||||||
|
*
|
||||||
$lastoffset = $offset = 0;
|
* $lastoffset = $offset = 0;
|
||||||
$len = strlen($string);
|
* $len = strlen($string);
|
||||||
|
*
|
||||||
while ($lastoffset<$len) {
|
* while ($lastoffset<$len) {
|
||||||
$offset = strpos($string, $delim, $lastoffset);
|
* $offset = strpos($string, $delim, $lastoffset);
|
||||||
$key = substr($string, $lastoffset, $offset-$lastoffset);
|
* $key = substr($string, $lastoffset, $offset-$lastoffset);
|
||||||
//echo 'parsing key: ', $key, $offset, chr(10);
|
* //echo 'parsing key: ', $key, $offset, chr(10);
|
||||||
|
*
|
||||||
$lastoffset = $offset + 1;
|
* $lastoffset = $offset + 1;
|
||||||
|
*
|
||||||
if (!ctype_upper($key))
|
* if (!ctype_upper($key))
|
||||||
trigger_error("Failed parsing \"$string\"
|
* trigger_error("Failed parsing \"$string\"
|
||||||
keys were supposed to be UPPERCASE", E_USER_ERROR);
|
* keys were supposed to be UPPERCASE", E_USER_ERROR);
|
||||||
|
*
|
||||||
$offset = strpos($string, $delim, $lastoffset);
|
* $offset = strpos($string, $delim, $lastoffset);
|
||||||
|
*
|
||||||
if ($offset===false)
|
* if ($offset===false)
|
||||||
$offset = $len;
|
* $offset = $len;
|
||||||
|
*
|
||||||
$val = substr($string, $lastoffset, $offset-$lastoffset);
|
* $val = substr($string, $lastoffset, $offset-$lastoffset);
|
||||||
|
*
|
||||||
//echo 'parsing value ', $val, $offset, chr(10);
|
* //echo 'parsing value ', $val, $offset, chr(10);
|
||||||
|
*
|
||||||
$lastoffset = $offset + 1;
|
* $lastoffset = $offset + 1;
|
||||||
|
*
|
||||||
$arr[$key] = $val;
|
* $arr[$key] = $val;
|
||||||
|
*
|
||||||
}
|
* }
|
||||||
return $arr;
|
* return $arr;
|
||||||
|
*
|
||||||
}*/
|
* }
|
||||||
|
*/
|
||||||
|
|
||||||
// function prototype:
|
// function prototype:
|
||||||
// array utils_kimplode(string $string, string $delim='|')
|
// array utils_kimplode(string $string, string $delim='|')
|
||||||
@ -155,9 +162,7 @@ if (!function_exists('fnmatch')) {
|
|||||||
// key1|value1|key2|value2 , etc.
|
// key1|value1|key2|value2 , etc.
|
||||||
// the array will look like
|
// the array will look like
|
||||||
// $arr['key1'] = 'value1'; $arr['key2'] = 'value2'; etc.
|
// $arr['key1'] = 'value1'; $arr['key2'] = 'value2'; etc.
|
||||||
|
|
||||||
function utils_kimplode($arr, $delim = '|') {
|
function utils_kimplode($arr, $delim = '|') {
|
||||||
|
|
||||||
$string = "";
|
$string = "";
|
||||||
foreach ($arr as $k => $val) {
|
foreach ($arr as $k => $val) {
|
||||||
if ($val)
|
if ($val)
|
||||||
@ -167,12 +172,10 @@ if (!function_exists('fnmatch')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* @todo send mail to admin
|
* @todo send mail to admin
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
function &utils_explode_recursive($array, &$string, $rdelim, $ldelim = '', $outerldelim = '', $outerrdelim = '') {
|
function &utils_explode_recursive($array, &$string, $rdelim, $ldelim = '', $outerldelim = '', $outerrdelim = '') {
|
||||||
|
|
||||||
$string .= $outerldelim;
|
$string .= $outerldelim;
|
||||||
|
|
||||||
while ($val = array_shift($array)) {
|
while ($val = array_shift($array)) {
|
||||||
@ -185,19 +188,12 @@ if (!function_exists('fnmatch')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$string .= $ldelim;
|
$string .= $ldelim;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$string .= $outerrdelim;
|
$string .= $outerrdelim;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function utils_validateinput($str) {
|
function utils_validateinput($str) {
|
||||||
|
|
||||||
if (preg_match('/[^a-z0-9\-_]/i', $str)) {
|
if (preg_match('/[^a-z0-9\-_]/i', $str)) {
|
||||||
trigger_error("String \"$str\" is not a valid input", E_USER_ERROR);
|
trigger_error("String \"$str\" is not a valid input", E_USER_ERROR);
|
||||||
// return false;
|
// return false;
|
||||||
@ -214,9 +210,7 @@ if (!function_exists('fnmatch')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function utils_status_header($status) {
|
function utils_status_header($status) {
|
||||||
|
|
||||||
switch ($status) {
|
switch ($status) {
|
||||||
case 301:
|
case 301:
|
||||||
header("HTTP/1.1 301 Moved Permanently");
|
header("HTTP/1.1 301 Moved Permanently");
|
||||||
@ -227,15 +221,12 @@ if (!function_exists('fnmatch')) {
|
|||||||
case 404:
|
case 404:
|
||||||
header("HTTP/1.1 404 Not Found");
|
header("HTTP/1.1 404 Not Found");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// code from php.net ;)
|
// code from php.net ;)
|
||||||
// defaults to index.php ;)
|
// defaults to index.php ;)
|
||||||
function utils_redirect($location = "", $absolute_path = false, $red_type = null) {
|
function utils_redirect($location = "", $absolute_path = false, $red_type = null) {
|
||||||
|
|
||||||
if (!$absolute_path)
|
if (!$absolute_path)
|
||||||
$location = BLOG_BASEURL . $location;
|
$location = BLOG_BASEURL . $location;
|
||||||
|
|
||||||
@ -246,17 +237,14 @@ if (!function_exists('fnmatch')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exit();
|
exit();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* utils_geturlstring()
|
* utils_geturlstring()
|
||||||
*
|
*
|
||||||
* @return string complete url string as displayed in the browser
|
* @return string complete url string as displayed in the browser
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function utils_geturlstring() {
|
function utils_geturlstring() {
|
||||||
$str = BLOG_BASEURL . $_SERVER ['PHP_SELF'];
|
$str = BLOG_BASEURL . $_SERVER ['PHP_SELF'];
|
||||||
if ($_SERVER ['QUERY_STRING'])
|
if ($_SERVER ['QUERY_STRING'])
|
||||||
@ -269,21 +257,18 @@ if (!function_exists('fnmatch')) {
|
|||||||
// this can be improved, anyway for now I'd just
|
// this can be improved, anyway for now I'd just
|
||||||
// do a quick & dirty solution :)
|
// do a quick & dirty solution :)
|
||||||
function utils_array_merge($arr1, $arr2) {
|
function utils_array_merge($arr1, $arr2) {
|
||||||
|
|
||||||
$len = count($arr1 [0]);
|
$len = count($arr1 [0]);
|
||||||
|
|
||||||
foreach ($arr2 as $k => $v)
|
foreach ($arr2 as $k => $v)
|
||||||
$arr2[$k]=array_pad((Array) $v, $len, null);
|
$arr2 [$k] = array_pad((array) $v, $len, null);
|
||||||
|
|
||||||
return array_merge($arr1, $arr2);
|
return array_merge($arr1, $arr2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Simple function to replicate PHP 5 behaviour
|
* Simple function to replicate PHP 5 behaviour
|
||||||
*/
|
*/
|
||||||
function utils_microtime()
|
function utils_microtime() {
|
||||||
{
|
|
||||||
list ($usec, $sec) = explode(" ", microtime());
|
list ($usec, $sec) = explode(" ", microtime());
|
||||||
return ((float) $usec + (float) $sec);
|
return ((float) $usec + (float) $sec);
|
||||||
}
|
}
|
||||||
@ -296,19 +281,16 @@ if (!function_exists('fnmatch')) {
|
|||||||
}
|
}
|
||||||
if ($i)
|
if ($i)
|
||||||
$rest = substr($string, $i);
|
$rest = substr($string, $i);
|
||||||
else $rest = $string;
|
else
|
||||||
|
$rest = $string;
|
||||||
|
|
||||||
return $i;
|
return $i;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function utils_mail($from, $subject, $message, $headers = '') {
|
function utils_mail($from, $subject, $message, $headers = '') {
|
||||||
global $fp_config;
|
global $fp_config;
|
||||||
if ($headers == '') {
|
if ($headers == '') {
|
||||||
$headers = "MIME-Version: 1.0\n" .
|
$headers = "MIME-Version: 1.0\n" . "From: " . $from . "\n" . "Content-Type: text/plain; charset=\"" . $fp_config ['general'] ['charset'] . "\"\n";
|
||||||
"From: " . $from . "\n" .
|
|
||||||
"Content-Type: text/plain; charset=\"" . $fp_config['general']['charset'] . "\"\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return mail($fp_config ['general'] ['email'], $subject, $message, $headers);
|
return mail($fp_config ['general'] ['email'], $subject, $message, $headers);
|
||||||
@ -327,8 +309,7 @@ if (!function_exists('fnmatch')) {
|
|||||||
return $IP == '::';
|
return $IP == '::';
|
||||||
|
|
||||||
// Check if part is in IPv4 format
|
// Check if part is in IPv4 format
|
||||||
if (strpos($IP, '.'))
|
if (strpos($IP, '.')) {
|
||||||
{
|
|
||||||
$lastcolon = strrpos($IP, ':');
|
$lastcolon = strrpos($IP, ':');
|
||||||
if (!($lastcolon && validateIPv4(substr($IP, $lastcolon + 1))))
|
if (!($lastcolon && validateIPv4(substr($IP, $lastcolon + 1))))
|
||||||
return false;
|
return false;
|
||||||
@ -338,14 +319,12 @@ if (!function_exists('fnmatch')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check uncompressed
|
// check uncompressed
|
||||||
if (strpos($IP, '::') === false)
|
if (strpos($IP, '::') === false) {
|
||||||
{
|
|
||||||
return preg_match('/^(?:[a-f0-9]{1,4}:){7}[a-f0-9]{1,4}$/i', $IP);
|
return preg_match('/^(?:[a-f0-9]{1,4}:){7}[a-f0-9]{1,4}$/i', $IP);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check colon-count for compressed format
|
// check colon-count for compressed format
|
||||||
if (substr_count($IP, ':') < 8)
|
if (substr_count($IP, ':') < 8) {
|
||||||
{
|
|
||||||
return preg_match('/^(?::|(?:[a-f0-9]{1,4}:)+):(?:(?:[a-f0-9]{1,4}:)*[a-f0-9]{1,4})?$/i', $IP);
|
return preg_match('/^(?::|(?:[a-f0-9]{1,4}:)+):(?:(?:[a-f0-9]{1,4}:)*[a-f0-9]{1,4})?$/i', $IP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,25 +333,19 @@ if (!function_exists('fnmatch')) {
|
|||||||
|
|
||||||
// get client IP
|
// get client IP
|
||||||
function utils_ipget() {
|
function utils_ipget() {
|
||||||
|
|
||||||
$ip = '';
|
$ip = '';
|
||||||
|
|
||||||
if (!empty($_SERVER ['HTTP_CLIENT_IP'])) {
|
if (!empty($_SERVER ['HTTP_CLIENT_IP'])) {
|
||||||
$ip = $_SERVER ['HTTP_CLIENT_IP'];
|
$ip = $_SERVER ['HTTP_CLIENT_IP'];
|
||||||
}
|
} elseif (!empty($_SERVER ['HTTP_X_FORWARDED_FOR'])) {
|
||||||
elseif ( !empty ( $_SERVER[ 'HTTP_X_FORWARDED_FOR' ] ) ) {
|
|
||||||
$ip = $_SERVER ['HTTP_X_FORWARDED_FOR'];
|
$ip = $_SERVER ['HTTP_X_FORWARDED_FOR'];
|
||||||
}
|
} elseif (!empty($_SERVER ['REMOTE_ADDR'])) {
|
||||||
elseif ( !empty ( $_SERVER[ 'REMOTE_ADDR' ] ) ) {
|
|
||||||
$ip = $_SERVER ['REMOTE_ADDR'];
|
$ip = $_SERVER ['REMOTE_ADDR'];
|
||||||
}
|
} elseif (getenv("HTTP_CLIENT_IP")) {
|
||||||
elseif ( getenv( "HTTP_CLIENT_IP" ) ) {
|
|
||||||
$ip = getenv("HTTP_CLIENT_IP");
|
$ip = getenv("HTTP_CLIENT_IP");
|
||||||
}
|
} elseif (getenv("HTTP_X_FORWARDED_FOR")) {
|
||||||
elseif ( getenv( "HTTP_X_FORWARDED_FOR" ) ) {
|
|
||||||
$ip = getenv("HTTP_X_FORWARDED_FOR");
|
$ip = getenv("HTTP_X_FORWARDED_FOR");
|
||||||
}
|
} elseif (getenv("REMOTE_ADDR")) {
|
||||||
elseif ( getenv( "REMOTE_ADDR") ) {
|
|
||||||
$ip = getenv("REMOTE_ADDR");
|
$ip = getenv("REMOTE_ADDR");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -381,8 +354,6 @@ if (!function_exists('fnmatch')) {
|
|||||||
} else {
|
} else {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function utils_nocache_headers() {
|
function utils_nocache_headers() {
|
||||||
@ -395,14 +366,15 @@ if (!function_exists('fnmatch')) {
|
|||||||
// from http://nadeausoftware.com/articles/2007/06/php_tip_how_get_web_page_using_curl
|
// from http://nadeausoftware.com/articles/2007/06/php_tip_how_get_web_page_using_curl
|
||||||
// code under OSI BSD
|
// code under OSI BSD
|
||||||
/**
|
/**
|
||||||
* Get a web file (HTML, XHTML, XML, image, etc.) from a URL. Return an
|
* Get a web file (HTML, XHTML, XML, image, etc.) from a URL.
|
||||||
|
* Return an
|
||||||
* array containing the HTTP server response header fields and content.
|
* array containing the HTTP server response header fields and content.
|
||||||
*/
|
*/
|
||||||
function utils_geturl($url) {
|
function utils_geturl($url) {
|
||||||
/*
|
/*
|
||||||
if (ini_get('allow_url_fopen')) {
|
* if (ini_get('allow_url_fopen')) {
|
||||||
return array('content' => io_load_file($url));
|
* return array('content' => io_load_file($url));
|
||||||
}
|
* }
|
||||||
*/
|
*/
|
||||||
if (!function_exists('curl_init')) {
|
if (!function_exists('curl_init')) {
|
||||||
trigger_error('curl extension is not installed');
|
trigger_error('curl extension is not installed');
|
||||||
@ -418,7 +390,7 @@ function utils_geturl($url) {
|
|||||||
CURLOPT_AUTOREFERER => true, // set referer on redirect
|
CURLOPT_AUTOREFERER => true, // set referer on redirect
|
||||||
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
|
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
|
||||||
CURLOPT_TIMEOUT => 120, // timeout on response
|
CURLOPT_TIMEOUT => 120, // timeout on response
|
||||||
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
|
CURLOPT_MAXREDIRS => 10 // stop after 10 redirects
|
||||||
);
|
);
|
||||||
|
|
||||||
$ch = curl_init($url);
|
$ch = curl_init($url);
|
||||||
@ -435,10 +407,7 @@ function utils_geturl($url) {
|
|||||||
return $header;
|
return $header;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function utils_checksmarty() {
|
function utils_checksmarty() {
|
||||||
|
|
||||||
if (!file_exists(SMARTY_DIR . 'Smarty.class.php')) {
|
if (!file_exists(SMARTY_DIR . 'Smarty.class.php')) {
|
||||||
$err = <<<ERR
|
$err = <<<ERR
|
||||||
Fatal error: Smarty is not installed; please download it from <a href="http://smarty.php.net">http://smarty.php.net</a>; you will
|
Fatal error: Smarty is not installed; please download it from <a href="http://smarty.php.net">http://smarty.php.net</a>; you will
|
||||||
@ -446,13 +415,28 @@ function utils_geturl($url) {
|
|||||||
ERR;
|
ERR;
|
||||||
trigger_error($err, E_USER_ERROR);
|
trigger_error($err, E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function fplog($str) {
|
function fplog($str) {
|
||||||
if (!defined('DEBUG_MODE'))
|
if (!defined('DEBUG_MODE'))
|
||||||
echo "\n[DEBUG] $str \n";
|
echo "\n[DEBUG] $str \n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shift an element with its key off the beginning of array.
|
||||||
|
* Just like array_shift(), but for an associative array.
|
||||||
|
*
|
||||||
|
* @param array $arr
|
||||||
|
* The input array
|
||||||
|
* @return unknown the shifted value, or NULL if array is empty or is not an array
|
||||||
|
*/
|
||||||
|
function utils_array_kshift(&$arr) {
|
||||||
|
list ($k) = array_keys($arr);
|
||||||
|
$r = array(
|
||||||
|
$k => $arr [$k]
|
||||||
|
);
|
||||||
|
unset($arr [$k]);
|
||||||
|
return $r;
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -1,75 +1,74 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Plugin Name: Calendar
|
* Plugin Name: Calendar
|
||||||
Version: 1.1
|
* Version: 1.1
|
||||||
Plugin URI: http://flatpress.sf.net
|
* Plugin URI: http://flatpress.sf.net
|
||||||
Type: Block
|
* Type: Block
|
||||||
Description: Adds a Calendar block level element
|
* Description: Adds a Calendar block level element
|
||||||
Author: NoWhereMan
|
* Author: NoWhereMan
|
||||||
Author URI: http://flatpress.sf.net
|
* Author URI: http://flatpress.sf.net
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// PHP Calendar (version 2.3), written by Keith Devens
|
||||||
# PHP Calendar (version 2.3), written by Keith Devens
|
// http://keithdevens.com/software/php_calendar
|
||||||
# http://keithdevens.com/software/php_calendar
|
// see example at http://keithdevens.com/weblog
|
||||||
# see example at http://keithdevens.com/weblog
|
// License: http://keithdevens.com/software/license
|
||||||
# License: http://keithdevens.com/software/license
|
|
||||||
|
|
||||||
function generate_calendar($year, $month, $days = array(), $day_name_length = 3, $month_href = NULL, $first_day = 0, $pn = array()) {
|
function generate_calendar($year, $month, $days = array(), $day_name_length = 3, $month_href = NULL, $first_day = 0, $pn = array()) {
|
||||||
$first_of_month = gmmktime(0, 0, 0, $month, 1, $year);
|
$first_of_month = gmmktime(0, 0, 0, $month, 1, $year);
|
||||||
#remember that mktime will automatically correct if invalid dates are entered
|
// remember that mktime will automatically correct if invalid dates are entered
|
||||||
# for instance, mktime(0,0,0,12,32,1997) will be the date for Jan 1, 1998
|
// for instance, mktime(0,0,0,12,32,1997) will be the date for Jan 1, 1998
|
||||||
# this provides a built in "rounding" feature to generate_calendar()
|
// this provides a built in "rounding" feature to generate_calendar()
|
||||||
|
|
||||||
$day_names = array(); #generate all the day names according to the current locale
|
$day_names = array(); // generate all the day names according to the current locale
|
||||||
for($n=0,$t=(3+$first_day)*86400; $n<7; $n++,$t+=86400) #January 4, 1970 was a Sunday
|
for($n = 0, $t = (3 + $first_day) * 86400; $n < 7; $n++, $t += 86400) // January 4, 1970 was a Sunday
|
||||||
$day_names[$n] = ucfirst(date_strformat('%A',$t)); #%A means full textual day name
|
$day_names [$n] = ucfirst(date_strformat('%A', $t)); // %A means full textual day name
|
||||||
|
|
||||||
list ($month, $year, $month_name, $weekday) = explode(',', date_strformat('%m,%Y,%B,%w', $first_of_month));
|
list ($month, $year, $month_name, $weekday) = explode(',', date_strformat('%m,%Y,%B,%w', $first_of_month));
|
||||||
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
|
$weekday = ($weekday + 7 - $first_day) % 7; // adjust for $first_day
|
||||||
$title = htmlentities(ucfirst($month_name)).' '.$year; #note that some locales don't capitalize month and day names
|
$title = htmlentities(ucfirst($month_name)) . ' ' . $year; // note that some locales don't capitalize month and day names
|
||||||
|
|
||||||
|
// Begin calendar. Uses a real <caption>. See http://diveintomark.org/archives/2002/07/03
|
||||||
|
|
||||||
#Begin calendar. Uses a real <caption>. See http://diveintomark.org/archives/2002/07/03
|
|
||||||
// PHP7 compatibility: Since $pn is never passed, we do not need to create "previous" and "next" elements.
|
// PHP7 compatibility: Since $pn is never passed, we do not need to create "previous" and "next" elements.
|
||||||
// Commented out to prevent deprecated each() function from being executed.
|
|
||||||
$p = '';
|
$p = '';
|
||||||
$n = '';
|
$n = '';
|
||||||
/*
|
// Commented out to prevent deprecated each() function from being executed.
|
||||||
@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
|
// @list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
|
||||||
if($p) $p = '<span class="calendar-prev">'.($pl ? '<a href="'.($pl).'">'.$p.'</a>' : $p).'</span> ';
|
// if($p) $p = '<span class="calendar-prev">'.($pl ? '<a href="'.($pl).'">'.$p.'</a>' : $p).'</span> ';
|
||||||
if($n) $n = ' <span class="calendar-next">'.($nl ? '<a href="'.($nl).'">'.$n.'</a>' : $n).'</span>';
|
// if($n) $n = ' <span class="calendar-next">'.($nl ? '<a href="'.($nl).'">'.$n.'</a>' : $n).'</span>';
|
||||||
*/
|
|
||||||
$calendar = '<table class="calendar">'."\n".
|
|
||||||
'<caption class="calendar-month">'.$p.($month_href ? '<a href="'.($month_href).'">'.$title.'</a>' : $title).$n."</caption>\n<tr>";
|
|
||||||
|
|
||||||
if($day_name_length){ #if the day names should be shown ($day_name_length > 0)
|
$calendar = '<table class="calendar">' . "\n" . '<caption class="calendar-month">' . $p . ($month_href ? '<a href="' . ($month_href) . '">' . $title . '</a>' : $title) . $n . "</caption>\n<tr>";
|
||||||
#if day_name_length is >3, the full name of the day will be printed
|
|
||||||
|
if ($day_name_length) { // if the day names should be shown ($day_name_length > 0)
|
||||||
|
// if day_name_length is >3, the full name of the day will be printed
|
||||||
foreach ($day_names as $d)
|
foreach ($day_names as $d)
|
||||||
$calendar .= '<th abbr="' . htmlentities($d) . '">' . htmlentities($day_name_length < 4 ? substr($d, 0, $day_name_length) : $d) . '</th>';
|
$calendar .= '<th abbr="' . htmlentities($d) . '">' . htmlentities($day_name_length < 4 ? substr($d, 0, $day_name_length) : $d) . '</th>';
|
||||||
$calendar .= "</tr>\n<tr>";
|
$calendar .= "</tr>\n<tr>";
|
||||||
}
|
}
|
||||||
|
|
||||||
if($weekday > 0) $calendar .= '<td colspan="'.$weekday.'"> </td>'; #initial 'empty' days
|
if ($weekday > 0)
|
||||||
|
$calendar .= '<td colspan="' . $weekday . '"> </td>'; // initial 'empty' days
|
||||||
for($day = 1, $days_in_month = gmdate('t', $first_of_month); $day <= $days_in_month; $day++, $weekday++) {
|
for($day = 1, $days_in_month = gmdate('t', $first_of_month); $day <= $days_in_month; $day++, $weekday++) {
|
||||||
if ($weekday == 7) {
|
if ($weekday == 7) {
|
||||||
$weekday = 0; #start a new week
|
$weekday = 0; // start a new week
|
||||||
$calendar .= "</tr>\n<tr>";
|
$calendar .= "</tr>\n<tr>";
|
||||||
}
|
}
|
||||||
if (isset($days [$day]) and is_array($days [$day])) {
|
if (isset($days [$day]) and is_array($days [$day])) {
|
||||||
@list ($link, $classes, $content) = $days [$day];
|
@list ($link, $classes, $content) = $days [$day];
|
||||||
if(is_null($content)) $content = $day;
|
if (is_null($content))
|
||||||
$calendar .= '<td'.($classes ? ' class="'.htmlspecialchars($classes).'">' : '>').
|
$content = $day;
|
||||||
($link ? '<a class="calendar-day" href="'.($link).'">'.$content.'</a>' : $content).'</td>';
|
$calendar .= '<td' . ($classes ? ' class="' . htmlspecialchars($classes) . '">' : '>') . ($link ? '<a class="calendar-day" href="' . ($link) . '">' . $content . '</a>' : $content) . '</td>';
|
||||||
|
} else
|
||||||
|
$calendar .= "<td>$day</td>";
|
||||||
}
|
}
|
||||||
else $calendar .= "<td>$day</td>";
|
if ($weekday != 7)
|
||||||
}
|
$calendar .= '<td colspan="' . (7 - $weekday) . '"> </td>'; // remaining "empty" days
|
||||||
if($weekday != 7) $calendar .= '<td colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days
|
|
||||||
|
|
||||||
return $calendar . "</tr>\n</table>\n";
|
return $calendar . "</tr>\n</table>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
function plugin_calendar_widget() {
|
function plugin_calendar_widget() {
|
||||||
|
|
||||||
global $fp_params;
|
global $fp_params;
|
||||||
|
|
||||||
$y = isset($fp_params ['y']) ? $fp_params ['y'] : date('y');
|
$y = isset($fp_params ['y']) ? $fp_params ['y'] : date('y');
|
||||||
@ -77,8 +76,12 @@ function plugin_calendar_widget() {
|
|||||||
|
|
||||||
global $fpdb;
|
global $fpdb;
|
||||||
|
|
||||||
$q = new FPDB_Query(array('fullparse'=>false,'y'=>$y,'m'=>$m, 'count' => -1), null);
|
$q = new FPDB_Query(array(
|
||||||
|
'fullparse' => false,
|
||||||
|
'y' => $y,
|
||||||
|
'm' => $m,
|
||||||
|
'count' => -1
|
||||||
|
), null);
|
||||||
|
|
||||||
$days = array();
|
$days = array();
|
||||||
|
|
||||||
@ -88,8 +91,10 @@ function plugin_calendar_widget() {
|
|||||||
$date = date_from_id($id);
|
$date = date_from_id($id);
|
||||||
$d = (int) $date ['d'];
|
$d = (int) $date ['d'];
|
||||||
|
|
||||||
$days[$d] = array(get_day_link($y, $m, str_pad($d, 2, '0', STR_PAD_LEFT)), 'linked-day');
|
$days [$d] = array(
|
||||||
|
get_day_link($y, $m, str_pad($d, 2, '0', STR_PAD_LEFT)),
|
||||||
|
'linked-day'
|
||||||
|
);
|
||||||
|
|
||||||
$count++;
|
$count++;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user