function cache_instructions($pi, $params = array()) { global $Config; global $DBInfo; $pagename = $this->name; // update aliases if (!empty($Config['use_alias'])) { $ac = new Cache_text('alias'); // is it removed ? if ($ac->exists($pagename) and empty($pi['#alias']) and empty($pi['#title'])) { // remove aliases store_aliases($pagename, array()); } else { if (!$ac->exists($pagename) or $ac->mtime($pagename) < $this->mtime() or !empty($_GET['update_alias'])) { $as = array(); // parse #alias if (!empty($pi['#alias'])) { $as = get_csv($pi['#alias']); } // add #title as a alias if (!empty($pi['#title'])) { $as[] = $pi['#title']; } // update aliases store_aliases($pagename, $as); } } } // update redirects cache $redirect = isset($pi['#redirect'][0]) ? $pi['#redirect'] : null; update_redirects($pagename, $redirect, $params['refresh']); if (!empty($Config['use_keywords']) or !empty($Config['use_tagging']) or !empty($_GET['update_keywords'])) { $tcache = new Cache_text('keyword'); $cache = new Cache_text('keywords'); $cur = $tcache->fetch($pagename); if (empty($cur)) { $cur = array(); } $keys = array(); if (empty($pi['#keywords'])) { $tcache->remove($pagename); } else { $keys = explode(',', $pi['#keywords']); $keys = array_map('trim', $keys); if (!$tcache->exists($pagename) or $tcache->mtime($pagename) < $this->mtime() or !empty($_GET['update_keywords'])) { $tcache->update($pagename, $keys); } } $adds = array_diff($keys, $cur); $dels = array_diff($cur, $keys); // merge new keywords foreach ($adds as $a) { if (!isset($a[0])) { continue; } $l = $cache->fetch($a); if (!is_array($l)) { $l = array(); } $l = array_merge($l, array($pagename)); $cache->update($a, $l); } // remove deleted keywords foreach ($dels as $d) { if (!isset($d[0])) { continue; } $l = $cache->fetch($d); if (!is_array($l)) { $l = array(); } $l = array_diff($l, array($pagename)); $cache->update($d, $l); } } if (!empty($pi['#title']) and !empty($Config['use_titlecache'])) { $tc = new Cache_text('title'); $old = $tc->fetch($pagename); if (!isset($pi['#title'])) { $tc->remove($pagename); } else { if ($old != $pi['#title'] or !$tcache->exists($pagename) or !empty($_GET['update_title'])) { $tc->update($pagename, $pi['#title']); } } } return; }
function cache_instructions($pi, $params = array()) { global $Config; global $DBInfo; $pagename = $this->name; // update aliases if (!empty($Config['use_alias'])) { $ac = new Cache_text('alias'); // is it removed ? if ($ac->exists($pagename) and empty($pi['#alias']) and empty($pi['#title'])) { // remove aliases store_aliases($pagename, array()); } else { if (!$ac->exists($pagename) or $ac->mtime($pagename) < $this->mtime() or !empty($_GET['update_alias'])) { $as = array(); // parse #alias if (!empty($pi['#alias'])) { $as = get_csv($pi['#alias']); } // add #title as a alias if (!empty($pi['#title'])) { $as[] = $pi['#title']; } // update aliases store_aliases($pagename, $as); } } } // update #redirect $rc = new Cache_Text('redirect'); $old = $rc->fetch($pagename); if ($old or isset($pi['#redirect'][0])) { // update invert redirect index $rc2 = new Cache_Text('redirects'); if (!empty($params['refresh']) or $old != $pi['#redirect']) { // update direct cache $rc->update($pagename, $pi['#redirect']); $nr = $pi['#redirect']; if (($p = strpos($nr, '#')) > 0) { // get pagename only //$anchor = substr($nr, $p); $nr = substr($nr, 0, $p); } if (!isset($nr[0])) { $rc->remove($pagename); } else { if (!preg_match('@^https?://@', $nr)) { // not a URL redirect // add redirect links $redirects = $rc2->fetch($nr); if (empty($redirects)) { $redirects = array(); } $redirects = array_merge($redirects, array($pagename)); $rc2->update($nr, $redirects); } } while ($old != '' and $old != false) { // get pagename only if (($p = strpos($old, '#')) > 0) { //$anchor = substr($old, $p); $old = substr($old, 0, $p); } if ($nr == $old) { break; } // check A#s-1 ~ A#s-2 redirects // delete redirect links $l = $rc2->fetch($old); if ($l !== false and is_array($l)) { $redirects = array_diff($l, array($pagename)); if (empty($redirects)) { $rc2->remove($old); } else { $rc2->update($old, $redirects); } } break; } } } if (!empty($Config['use_keywords']) or !empty($Config['use_tagging']) or !empty($_GET['update_keywords'])) { $tcache = new Cache_text('keyword'); $cache = new Cache_text('keywords'); $cur = $tcache->fetch($pagename); if (empty($cur)) { $cur = array(); } $keys = array(); if (empty($pi['#keywords'])) { $tcache->remove($pagename); } else { $keys = explode(',', $pi['#keywords']); $keys = array_map('trim', $keys); if (!$tcache->exists($pagename) or $tcache->mtime($pagename) < $this->mtime() or !empty($_GET['update_keywords'])) { $tcache->update($pagename, $keys); } } $adds = array_diff($keys, $cur); $dels = array_diff($cur, $keys); // merge new keywords foreach ($adds as $a) { if (!isset($a[0])) { continue; } $l = $cache->fetch($a); if (!is_array($l)) { $l = array(); } $l = array_merge($l, array($pagename)); $cache->update($a, $l); } // remove deleted keywords foreach ($dels as $d) { if (!isset($d[0])) { continue; } $l = $cache->fetch($d); if (!is_array($l)) { $l = array(); } $l = array_diff($l, array($pagename)); $cache->update($d, $l); } } if (!empty($pi['#title']) and !empty($Config['use_titlecache'])) { $tc = new Cache_text('title'); $old = $tc->fetch($pagename); if (!isset($pi['#title'])) { $tc->remove($pagename); } else { if ($old != $pi['#title'] or !$tcache->exists($pagename) or !empty($_GET['update_title'])) { $tc->update($pagename, $pi['#title']); } } } return; }