@@ -31,24 +31,24 @@ discard block |
||
| 31 | 31 | $baseurl = REFERENCES_URL . basename(__FILE__); |
| 32 | 32 | $artice_id = isset($_GET['article_id']) ? (int)$_GET['article_id'] : 0; |
| 33 | 33 | if ($artice_id == 0) { |
| 34 | - references_utils::redirect(_MD_REFERENCES_ERROR4, 'index.php', 4); |
|
| 34 | + references_utils::redirect(_MD_REFERENCES_ERROR4, 'index.php', 4); |
|
| 35 | 35 | } |
| 36 | 36 | $article = null; |
| 37 | 37 | $article = $h_references_articles->get($artice_id); |
| 38 | 38 | if (!is_object($article)) { |
| 39 | - references_utils::redirect(_MD_REFERENCES_ERROR4, 'index.php', 4); |
|
| 39 | + references_utils::redirect(_MD_REFERENCES_ERROR4, 'index.php', 4); |
|
| 40 | 40 | } |
| 41 | 41 | // Vérification des permissions |
| 42 | 42 | $handlers = references_handler::getInstance(); |
| 43 | 43 | if (!$handlers->h_references_articles->userCanSeeReference($article)) { |
| 44 | - references_utils::redirect(_NOPERM, 'index.php', 4); |
|
| 44 | + references_utils::redirect(_NOPERM, 'index.php', 4); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | // Chargement de la catégorie |
| 48 | 48 | $category = null; |
| 49 | 49 | $category = $h_references_categories->get($article->getVar('article_category_id')); |
| 50 | 50 | if (!is_object($category)) { |
| 51 | - references_utils::redirect(_MD_REFERENCES_ERROR2, 'index.php', 4); |
|
| 51 | + references_utils::redirect(_MD_REFERENCES_ERROR2, 'index.php', 4); |
|
| 52 | 52 | } |
| 53 | 53 | $xoopsTpl->assign('category', $category->toArray()); |
| 54 | 54 | $xoopsTpl->assign('article', $article->toArray()); |
@@ -57,8 +57,8 @@ discard block |
||
| 57 | 57 | |
| 58 | 58 | // Breadcrumb |
| 59 | 59 | $breadcrumb = array( |
| 60 | - $category->getUrl() => $category->getVar('category_title'), |
|
| 61 | - $baseurl => $article->getVar('article_title') |
|
| 60 | + $category->getUrl() => $category->getVar('category_title'), |
|
| 61 | + $baseurl => $article->getVar('article_title') |
|
| 62 | 62 | ); |
| 63 | 63 | $xoopsTpl->assign('breadcrumb', references_utils::breadcrumb($breadcrumb)); |
| 64 | 64 | |
@@ -68,9 +68,9 @@ discard block |
||
| 68 | 68 | $xoTheme->addScript(REFERENCES_JS_URL . 'js/mootools.js'); |
| 69 | 69 | $xoTheme->addScript(REFERENCES_JS_URL . 'js/mootools-1.2-more.js'); |
| 70 | 70 | if (isset($xoopsConfig) && file_exists(REFERENCES_PATH . 'language/' . $xoopsConfig['language'] . '/slimbox.js')) { |
| 71 | - $xoTheme->addScript(REFERENCES_URL . 'language/' . $xoopsConfig['language'] . '/slimbox.js'); |
|
| 71 | + $xoTheme->addScript(REFERENCES_URL . 'language/' . $xoopsConfig['language'] . '/slimbox.js'); |
|
| 72 | 72 | } else { |
| 73 | - $xoTheme->addScript(REFERENCES_JS_URL . 'js/slimbox.js'); |
|
| 73 | + $xoTheme->addScript(REFERENCES_JS_URL . 'js/slimbox.js'); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | $categoriesSelect = $h_references_categories->getCategoriesSelect('categoriesSelect', $category->getVar('category_id')); |
@@ -24,12 +24,12 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | * @param integer $article_id Le numéro de la référence |
| 26 | 26 | */ |
| 27 | -require __DIR__ . '/header.php'; |
|
| 27 | +require __DIR__.'/header.php'; |
|
| 28 | 28 | $xoopsOption['template_main'] = 'references_reference.tpl'; |
| 29 | -require XOOPS_ROOT_PATH . '/header.php'; |
|
| 29 | +require XOOPS_ROOT_PATH.'/header.php'; |
|
| 30 | 30 | |
| 31 | -$baseurl = REFERENCES_URL . basename(__FILE__); |
|
| 32 | -$artice_id = isset($_GET['article_id']) ? (int)$_GET['article_id'] : 0; |
|
| 31 | +$baseurl = REFERENCES_URL.basename(__FILE__); |
|
| 32 | +$artice_id = isset($_GET['article_id']) ? (int) $_GET['article_id'] : 0; |
|
| 33 | 33 | if ($artice_id == 0) { |
| 34 | 34 | references_utils::redirect(_MD_REFERENCES_ERROR4, 'index.php', 4); |
| 35 | 35 | } |
@@ -65,25 +65,25 @@ discard block |
||
| 65 | 65 | $xoopsTpl->assign('use_rss', references_utils::getModuleOption('use_rss')); |
| 66 | 66 | |
| 67 | 67 | // MooTools |
| 68 | -$xoTheme->addScript(REFERENCES_JS_URL . 'js/mootools.js'); |
|
| 69 | -$xoTheme->addScript(REFERENCES_JS_URL . 'js/mootools-1.2-more.js'); |
|
| 70 | -if (isset($xoopsConfig) && file_exists(REFERENCES_PATH . 'language/' . $xoopsConfig['language'] . '/slimbox.js')) { |
|
| 71 | - $xoTheme->addScript(REFERENCES_URL . 'language/' . $xoopsConfig['language'] . '/slimbox.js'); |
|
| 68 | +$xoTheme->addScript(REFERENCES_JS_URL.'js/mootools.js'); |
|
| 69 | +$xoTheme->addScript(REFERENCES_JS_URL.'js/mootools-1.2-more.js'); |
|
| 70 | +if (isset($xoopsConfig) && file_exists(REFERENCES_PATH.'language/'.$xoopsConfig['language'].'/slimbox.js')) { |
|
| 71 | + $xoTheme->addScript(REFERENCES_URL.'language/'.$xoopsConfig['language'].'/slimbox.js'); |
|
| 72 | 72 | } else { |
| 73 | - $xoTheme->addScript(REFERENCES_JS_URL . 'js/slimbox.js'); |
|
| 73 | + $xoTheme->addScript(REFERENCES_JS_URL.'js/slimbox.js'); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | $categoriesSelect = $h_references_categories->getCategoriesSelect('categoriesSelect', $category->getVar('category_id')); |
| 77 | 77 | $xoopsTpl->assign('categoriesSelect', $categoriesSelect); |
| 78 | -$xoTheme->addStylesheet(REFERENCES_JS_URL . 'css/slimbox.css'); |
|
| 79 | -$xoTheme->addStylesheet(REFERENCES_JS_URL . 'css/accordion.css'); |
|
| 78 | +$xoTheme->addStylesheet(REFERENCES_JS_URL.'css/slimbox.css'); |
|
| 79 | +$xoTheme->addStylesheet(REFERENCES_JS_URL.'css/accordion.css'); |
|
| 80 | 80 | $xoopsTpl->assign('isAdmin', references_utils::isAdmin()); |
| 81 | 81 | |
| 82 | 82 | // **************************************************************************************************************************** |
| 83 | 83 | $xoopsTpl->assign('thumbsWidth', references_utils::getModuleOption('thumbs_width')); |
| 84 | 84 | $xoopsTpl->assign('thumbsHeight', references_utils::getModuleOption('thumbs_height')); |
| 85 | 85 | |
| 86 | -$metaTitle = $article->getVar('article_title', 'n') . ' - ' . $xoopsModule->name(); |
|
| 86 | +$metaTitle = $article->getVar('article_title', 'n').' - '.$xoopsModule->name(); |
|
| 87 | 87 | $metaKeywords = references_utils::createMetaKeywords($article->getVar('article_text', 'n')); |
| 88 | 88 | references_utils::setMetas($metaTitle, $metaTitle, $metaKeywords); |
| 89 | -require XOOPS_ROOT_PATH . '/footer.php'; |
|
| 89 | +require XOOPS_ROOT_PATH.'/footer.php'; |
|
@@ -41,9 +41,9 @@ discard block |
||
| 41 | 41 | $xoTheme->addScript(REFERENCES_JS_URL . 'js/mootools-1.2-more.js'); |
| 42 | 42 | |
| 43 | 43 | if (isset($xoopsConfig) && file_exists(REFERENCES_PATH . 'language/' . $xoopsConfig['language'] . '/slimbox.js')) { |
| 44 | - $xoTheme->addScript(REFERENCES_URL . 'language/' . $xoopsConfig['language'] . '/slimbox.js'); |
|
| 44 | + $xoTheme->addScript(REFERENCES_URL . 'language/' . $xoopsConfig['language'] . '/slimbox.js'); |
|
| 45 | 45 | } else { |
| 46 | - $xoTheme->addScript(REFERENCES_JS_URL . 'js/slimbox.js'); |
|
| 46 | + $xoTheme->addScript(REFERENCES_JS_URL . 'js/slimbox.js'); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | $categories = $h_references_categories->getCategories(); |
@@ -63,42 +63,42 @@ discard block |
||
| 63 | 63 | $refFounded = false; |
| 64 | 64 | $mostRecentReferenceDate = 0; |
| 65 | 65 | if ($limit > 0) { |
| 66 | - $uniqueCategories = $h_references_articles->getDistinctCategoriesIds(); |
|
| 67 | - foreach ($uniqueCategories as $categoryId) { |
|
| 68 | - $items = array(); |
|
| 69 | - $items = $h_references_articles->getRecentArticles($start, $limit, references_utils::getModuleOption('sort_field'), references_utils::getModuleOption('sort_order'), true, $categoryId); |
|
| 70 | - $categoryTitle = isset($categories[$categoryId]) ? $categories[$categoryId]->getVar('category_title') : ''; |
|
| 71 | - $categoryWeight = isset($categories[$categoryId]) ? $categories[$categoryId]->getVar('category_weight') : 0; |
|
| 72 | - if (count($items) > 0) { |
|
| 73 | - foreach ($items as $item) { |
|
| 74 | - $articleData = array(); |
|
| 75 | - $articleData = $item->toArray(); |
|
| 76 | - if ($item->getVar('article_id') == $article_id) { |
|
| 77 | - $xoopsTpl->assign('defaultArticle', $index); |
|
| 78 | - $refFounded = true; |
|
| 79 | - } |
|
| 80 | - ++$index; |
|
| 81 | - $articleData['article_category_id'] = $categoryId; |
|
| 82 | - $articleData['article_category_title'] = $categoryTitle; |
|
| 83 | - $articleData['article_category_weight'] = $categoryWeight; |
|
| 84 | - $categoriesForTemplate[$categoryWeight . '-' . $categoryId]['articles'][] = $articleData; |
|
| 85 | - $categoriesForTemplate[$categoryWeight . '-' . $categoryId]['categoryTitle'] = $categoryTitle; |
|
| 86 | - $categoriesForTemplate[$categoryWeight . '-' . $categoryId]['categoryId'] = $categoryId; |
|
| 87 | - if ($item->getVar('article_timestamp') > $mostRecentReferenceDate) { |
|
| 88 | - $mostRecentReferenceDate = $item->getVar('article_timestamp'); |
|
| 89 | - $lastTitle = strip_tags($item->getVar('article_title', 'n')) . ', ' . $item->getVar('article_date'); |
|
| 90 | - $lastKeywords = strip_tags($item->getVar('article_text', 'n')); |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - if (!$refFounded) { |
|
| 96 | - $xoopsTpl->assign('defaultArticle', 0); |
|
| 97 | - } |
|
| 98 | - if (count($categoriesForTemplate) > 0) { |
|
| 99 | - ksort($categoriesForTemplate); |
|
| 100 | - } |
|
| 101 | - $xoopsTpl->assign('categories', $categoriesForTemplate); |
|
| 66 | + $uniqueCategories = $h_references_articles->getDistinctCategoriesIds(); |
|
| 67 | + foreach ($uniqueCategories as $categoryId) { |
|
| 68 | + $items = array(); |
|
| 69 | + $items = $h_references_articles->getRecentArticles($start, $limit, references_utils::getModuleOption('sort_field'), references_utils::getModuleOption('sort_order'), true, $categoryId); |
|
| 70 | + $categoryTitle = isset($categories[$categoryId]) ? $categories[$categoryId]->getVar('category_title') : ''; |
|
| 71 | + $categoryWeight = isset($categories[$categoryId]) ? $categories[$categoryId]->getVar('category_weight') : 0; |
|
| 72 | + if (count($items) > 0) { |
|
| 73 | + foreach ($items as $item) { |
|
| 74 | + $articleData = array(); |
|
| 75 | + $articleData = $item->toArray(); |
|
| 76 | + if ($item->getVar('article_id') == $article_id) { |
|
| 77 | + $xoopsTpl->assign('defaultArticle', $index); |
|
| 78 | + $refFounded = true; |
|
| 79 | + } |
|
| 80 | + ++$index; |
|
| 81 | + $articleData['article_category_id'] = $categoryId; |
|
| 82 | + $articleData['article_category_title'] = $categoryTitle; |
|
| 83 | + $articleData['article_category_weight'] = $categoryWeight; |
|
| 84 | + $categoriesForTemplate[$categoryWeight . '-' . $categoryId]['articles'][] = $articleData; |
|
| 85 | + $categoriesForTemplate[$categoryWeight . '-' . $categoryId]['categoryTitle'] = $categoryTitle; |
|
| 86 | + $categoriesForTemplate[$categoryWeight . '-' . $categoryId]['categoryId'] = $categoryId; |
|
| 87 | + if ($item->getVar('article_timestamp') > $mostRecentReferenceDate) { |
|
| 88 | + $mostRecentReferenceDate = $item->getVar('article_timestamp'); |
|
| 89 | + $lastTitle = strip_tags($item->getVar('article_title', 'n')) . ', ' . $item->getVar('article_date'); |
|
| 90 | + $lastKeywords = strip_tags($item->getVar('article_text', 'n')); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + if (!$refFounded) { |
|
| 96 | + $xoopsTpl->assign('defaultArticle', 0); |
|
| 97 | + } |
|
| 98 | + if (count($categoriesForTemplate) > 0) { |
|
| 99 | + ksort($categoriesForTemplate); |
|
| 100 | + } |
|
| 101 | + $xoopsTpl->assign('categories', $categoriesForTemplate); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | $xoopsTpl->assign('isAdmin', references_utils::isAdmin()); |
@@ -22,14 +22,14 @@ discard block |
||
| 22 | 22 | /* |
| 23 | 23 | * Page d'index du module, liste des articles |
| 24 | 24 | */ |
| 25 | -require __DIR__ . '/header.php'; |
|
| 25 | +require __DIR__.'/header.php'; |
|
| 26 | 26 | $xoopsOption['template_main'] = 'references_index.tpl'; |
| 27 | -require XOOPS_ROOT_PATH . '/header.php'; |
|
| 28 | -require_once REFERENCES_PATH . 'class/registryfile.php'; |
|
| 27 | +require XOOPS_ROOT_PATH.'/header.php'; |
|
| 28 | +require_once REFERENCES_PATH.'class/registryfile.php'; |
|
| 29 | 29 | |
| 30 | 30 | $limit = references_utils::getModuleOption('items_index_page'); |
| 31 | 31 | $start = $index = 0; |
| 32 | -$article_id = isset($_GET['article_id']) ? (int)$_GET['article_id'] : 0; // Utiliser pour afficher un article particulier |
|
| 32 | +$article_id = isset($_GET['article_id']) ? (int) $_GET['article_id'] : 0; // Utiliser pour afficher un article particulier |
|
| 33 | 33 | |
| 34 | 34 | // Texte à afficher sur la page d'accueil |
| 35 | 35 | $registry = new references_registryfile(); |
@@ -37,13 +37,13 @@ discard block |
||
| 37 | 37 | $xoopsTpl->assign('use_rss', references_utils::getModuleOption('use_rss')); |
| 38 | 38 | |
| 39 | 39 | // MooTools |
| 40 | -$xoTheme->addScript(REFERENCES_JS_URL . 'js/mootools.js'); |
|
| 41 | -$xoTheme->addScript(REFERENCES_JS_URL . 'js/mootools-1.2-more.js'); |
|
| 40 | +$xoTheme->addScript(REFERENCES_JS_URL.'js/mootools.js'); |
|
| 41 | +$xoTheme->addScript(REFERENCES_JS_URL.'js/mootools-1.2-more.js'); |
|
| 42 | 42 | |
| 43 | -if (isset($xoopsConfig) && file_exists(REFERENCES_PATH . 'language/' . $xoopsConfig['language'] . '/slimbox.js')) { |
|
| 44 | - $xoTheme->addScript(REFERENCES_URL . 'language/' . $xoopsConfig['language'] . '/slimbox.js'); |
|
| 43 | +if (isset($xoopsConfig) && file_exists(REFERENCES_PATH.'language/'.$xoopsConfig['language'].'/slimbox.js')) { |
|
| 44 | + $xoTheme->addScript(REFERENCES_URL.'language/'.$xoopsConfig['language'].'/slimbox.js'); |
|
| 45 | 45 | } else { |
| 46 | - $xoTheme->addScript(REFERENCES_JS_URL . 'js/slimbox.js'); |
|
| 46 | + $xoTheme->addScript(REFERENCES_JS_URL.'js/slimbox.js'); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | $categories = $h_references_categories->getCategories(); |
@@ -52,8 +52,8 @@ discard block |
||
| 52 | 52 | $categoriesForTemplate = array(); |
| 53 | 53 | |
| 54 | 54 | //$xoTheme->addScript(REFERENCES_JS_URL.'js/accordion.js'); |
| 55 | -$xoTheme->addStylesheet(REFERENCES_JS_URL . 'css/slimbox.css'); |
|
| 56 | -$xoTheme->addStylesheet(REFERENCES_JS_URL . 'css/accordion.css'); |
|
| 55 | +$xoTheme->addStylesheet(REFERENCES_JS_URL.'css/slimbox.css'); |
|
| 56 | +$xoTheme->addStylesheet(REFERENCES_JS_URL.'css/accordion.css'); |
|
| 57 | 57 | |
| 58 | 58 | // **************************************************************************************************************************** |
| 59 | 59 | $xoopsTpl->assign('thumbsWidth', references_utils::getModuleOption('thumbs_width')); |
@@ -81,12 +81,12 @@ discard block |
||
| 81 | 81 | $articleData['article_category_id'] = $categoryId; |
| 82 | 82 | $articleData['article_category_title'] = $categoryTitle; |
| 83 | 83 | $articleData['article_category_weight'] = $categoryWeight; |
| 84 | - $categoriesForTemplate[$categoryWeight . '-' . $categoryId]['articles'][] = $articleData; |
|
| 85 | - $categoriesForTemplate[$categoryWeight . '-' . $categoryId]['categoryTitle'] = $categoryTitle; |
|
| 86 | - $categoriesForTemplate[$categoryWeight . '-' . $categoryId]['categoryId'] = $categoryId; |
|
| 84 | + $categoriesForTemplate[$categoryWeight.'-'.$categoryId]['articles'][] = $articleData; |
|
| 85 | + $categoriesForTemplate[$categoryWeight.'-'.$categoryId]['categoryTitle'] = $categoryTitle; |
|
| 86 | + $categoriesForTemplate[$categoryWeight.'-'.$categoryId]['categoryId'] = $categoryId; |
|
| 87 | 87 | if ($item->getVar('article_timestamp') > $mostRecentReferenceDate) { |
| 88 | 88 | $mostRecentReferenceDate = $item->getVar('article_timestamp'); |
| 89 | - $lastTitle = strip_tags($item->getVar('article_title', 'n')) . ', ' . $item->getVar('article_date'); |
|
| 89 | + $lastTitle = strip_tags($item->getVar('article_title', 'n')).', '.$item->getVar('article_date'); |
|
| 90 | 90 | $lastKeywords = strip_tags($item->getVar('article_text', 'n')); |
| 91 | 91 | } |
| 92 | 92 | } |
@@ -102,8 +102,8 @@ discard block |
||
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | $xoopsTpl->assign('isAdmin', references_utils::isAdmin()); |
| 105 | -$metaTitle = $lastTitle . ' - ' . $xoopsModule->name(); |
|
| 106 | -$metaKeywords = references_utils::createMetaKeywords($lastTitle . ' ' . $lastKeywords); |
|
| 105 | +$metaTitle = $lastTitle.' - '.$xoopsModule->name(); |
|
| 106 | +$metaKeywords = references_utils::createMetaKeywords($lastTitle.' '.$lastKeywords); |
|
| 107 | 107 | |
| 108 | 108 | references_utils::setMetas($metaTitle, $metaTitle, $metaKeywords); |
| 109 | -require XOOPS_ROOT_PATH . '/footer.php'; |
|
| 109 | +require XOOPS_ROOT_PATH.'/footer.php'; |
|
@@ -18,5 +18,5 @@ |
||
| 18 | 18 | * |
| 19 | 19 | * **************************************************************************** |
| 20 | 20 | */ |
| 21 | -require __DIR__ . '/../../mainfile.php'; |
|
| 22 | -require XOOPS_ROOT_PATH . '/include/notification_update.php'; |
|
| 21 | +require __DIR__.'/../../mainfile.php'; |
|
| 22 | +require XOOPS_ROOT_PATH.'/include/notification_update.php'; |
|
@@ -26,26 +26,26 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | function b_references_last_news_show($options) |
| 28 | 28 | { |
| 29 | - global $xoopsConfig; |
|
| 30 | - require XOOPS_ROOT_PATH . '/modules/references/include/common.php'; |
|
| 31 | - $block = array(); |
|
| 32 | - $start = 0; |
|
| 33 | - $limit = (int)$options[0]; |
|
| 34 | - if ($limit > 0) { |
|
| 35 | - $items = array(); |
|
| 36 | - $categories = array(); |
|
| 37 | - if (is_array($options) && count($options) > 1) { |
|
| 38 | - $categories = array_slice($options, 1); |
|
| 39 | - } |
|
| 40 | - $items = $h_references_articles->getRecentArticles($start, $limit, 'article_timestamp', 'DESC', true, $categories); |
|
| 41 | - if (count($items) > 0) { |
|
| 42 | - foreach ($items as $item) { |
|
| 43 | - $block['block_last_news'][] = $item->toArray(); |
|
| 44 | - } |
|
| 45 | - } |
|
| 46 | - } |
|
| 29 | + global $xoopsConfig; |
|
| 30 | + require XOOPS_ROOT_PATH . '/modules/references/include/common.php'; |
|
| 31 | + $block = array(); |
|
| 32 | + $start = 0; |
|
| 33 | + $limit = (int)$options[0]; |
|
| 34 | + if ($limit > 0) { |
|
| 35 | + $items = array(); |
|
| 36 | + $categories = array(); |
|
| 37 | + if (is_array($options) && count($options) > 1) { |
|
| 38 | + $categories = array_slice($options, 1); |
|
| 39 | + } |
|
| 40 | + $items = $h_references_articles->getRecentArticles($start, $limit, 'article_timestamp', 'DESC', true, $categories); |
|
| 41 | + if (count($items) > 0) { |
|
| 42 | + foreach ($items as $item) { |
|
| 43 | + $block['block_last_news'][] = $item->toArray(); |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - return $block; |
|
| 48 | + return $block; |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
@@ -56,26 +56,26 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | function b_references_last_news_edit($options) |
| 58 | 58 | { |
| 59 | - global $xoopsConfig; |
|
| 60 | - include XOOPS_ROOT_PATH . '/modules/references/include/common.php'; |
|
| 61 | - $handlers = references_handler::getInstance(); |
|
| 62 | - $categories = $handlers->h_references_categories->getListArray(); |
|
| 63 | - $form = ''; |
|
| 64 | - $form .= "<table border='0'>"; |
|
| 65 | - $form .= '<tr><td>' . _MB_REFERENCES_ITEMS_COUNT . "</td><td><input type='text' name='options[]' id='options' value='" . $options[0] . "' /></td></tr>\n"; |
|
| 66 | - $form .= '<tr><td>' . _MB_REFERENCES_CATEGORIES . "</td><td><select name='options[]' multiple='multiple'>"; |
|
| 67 | - $size = count($options); |
|
| 68 | - foreach ($categories as $Idcategory => $categoryName) { |
|
| 69 | - $sel = ''; |
|
| 70 | - for ($i = 1; $i < $size; ++$i) { |
|
| 71 | - if ($options[$i] == $Idcategory) { |
|
| 72 | - $sel = " selected='selected'"; |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - $form .= "<option value='$Idcategory' $sel>$categoryName</option>"; |
|
| 76 | - } |
|
| 77 | - $form .= "</select></td></tr>\n"; |
|
| 78 | - $form .= '</table>'; |
|
| 59 | + global $xoopsConfig; |
|
| 60 | + include XOOPS_ROOT_PATH . '/modules/references/include/common.php'; |
|
| 61 | + $handlers = references_handler::getInstance(); |
|
| 62 | + $categories = $handlers->h_references_categories->getListArray(); |
|
| 63 | + $form = ''; |
|
| 64 | + $form .= "<table border='0'>"; |
|
| 65 | + $form .= '<tr><td>' . _MB_REFERENCES_ITEMS_COUNT . "</td><td><input type='text' name='options[]' id='options' value='" . $options[0] . "' /></td></tr>\n"; |
|
| 66 | + $form .= '<tr><td>' . _MB_REFERENCES_CATEGORIES . "</td><td><select name='options[]' multiple='multiple'>"; |
|
| 67 | + $size = count($options); |
|
| 68 | + foreach ($categories as $Idcategory => $categoryName) { |
|
| 69 | + $sel = ''; |
|
| 70 | + for ($i = 1; $i < $size; ++$i) { |
|
| 71 | + if ($options[$i] == $Idcategory) { |
|
| 72 | + $sel = " selected='selected'"; |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + $form .= "<option value='$Idcategory' $sel>$categoryName</option>"; |
|
| 76 | + } |
|
| 77 | + $form .= "</select></td></tr>\n"; |
|
| 78 | + $form .= '</table>'; |
|
| 79 | 79 | |
| 80 | - return $form; |
|
| 80 | + return $form; |
|
| 81 | 81 | } |
@@ -27,10 +27,10 @@ discard block |
||
| 27 | 27 | function b_references_last_news_show($options) |
| 28 | 28 | { |
| 29 | 29 | global $xoopsConfig; |
| 30 | - require XOOPS_ROOT_PATH . '/modules/references/include/common.php'; |
|
| 30 | + require XOOPS_ROOT_PATH.'/modules/references/include/common.php'; |
|
| 31 | 31 | $block = array(); |
| 32 | 32 | $start = 0; |
| 33 | - $limit = (int)$options[0]; |
|
| 33 | + $limit = (int) $options[0]; |
|
| 34 | 34 | if ($limit > 0) { |
| 35 | 35 | $items = array(); |
| 36 | 36 | $categories = array(); |
@@ -57,13 +57,13 @@ discard block |
||
| 57 | 57 | function b_references_last_news_edit($options) |
| 58 | 58 | { |
| 59 | 59 | global $xoopsConfig; |
| 60 | - include XOOPS_ROOT_PATH . '/modules/references/include/common.php'; |
|
| 60 | + include XOOPS_ROOT_PATH.'/modules/references/include/common.php'; |
|
| 61 | 61 | $handlers = references_handler::getInstance(); |
| 62 | 62 | $categories = $handlers->h_references_categories->getListArray(); |
| 63 | 63 | $form = ''; |
| 64 | 64 | $form .= "<table border='0'>"; |
| 65 | - $form .= '<tr><td>' . _MB_REFERENCES_ITEMS_COUNT . "</td><td><input type='text' name='options[]' id='options' value='" . $options[0] . "' /></td></tr>\n"; |
|
| 66 | - $form .= '<tr><td>' . _MB_REFERENCES_CATEGORIES . "</td><td><select name='options[]' multiple='multiple'>"; |
|
| 65 | + $form .= '<tr><td>'._MB_REFERENCES_ITEMS_COUNT."</td><td><input type='text' name='options[]' id='options' value='".$options[0]."' /></td></tr>\n"; |
|
| 66 | + $form .= '<tr><td>'._MB_REFERENCES_CATEGORIES."</td><td><select name='options[]' multiple='multiple'>"; |
|
| 67 | 67 | $size = count($options); |
| 68 | 68 | foreach ($categories as $Idcategory => $categoryName) { |
| 69 | 69 | $sel = ''; |
@@ -22,44 +22,44 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | function references_tag_block_cloud_show($options) |
| 24 | 24 | { |
| 25 | - require XOOPS_ROOT_PATH . '/modules/references/include/common.php'; |
|
| 26 | - if (!references_utils::tagModuleExists()) { |
|
| 27 | - return false; |
|
| 28 | - } |
|
| 29 | - require_once XOOPS_ROOT_PATH . '/modules/tag/blocks/block.php'; |
|
| 25 | + require XOOPS_ROOT_PATH . '/modules/references/include/common.php'; |
|
| 26 | + if (!references_utils::tagModuleExists()) { |
|
| 27 | + return false; |
|
| 28 | + } |
|
| 29 | + require_once XOOPS_ROOT_PATH . '/modules/tag/blocks/block.php'; |
|
| 30 | 30 | |
| 31 | - return tag_block_cloud_show($options, 'references'); |
|
| 31 | + return tag_block_cloud_show($options, 'references'); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | function references_tag_block_cloud_edit($options) |
| 35 | 35 | { |
| 36 | - require XOOPS_ROOT_PATH . '/modules/references/include/common.php'; |
|
| 37 | - if (!references_utils::tagModuleExists()) { |
|
| 38 | - return false; |
|
| 39 | - } |
|
| 40 | - require_once XOOPS_ROOT_PATH . '/modules/tag/blocks/block.php'; |
|
| 36 | + require XOOPS_ROOT_PATH . '/modules/references/include/common.php'; |
|
| 37 | + if (!references_utils::tagModuleExists()) { |
|
| 38 | + return false; |
|
| 39 | + } |
|
| 40 | + require_once XOOPS_ROOT_PATH . '/modules/tag/blocks/block.php'; |
|
| 41 | 41 | |
| 42 | - return tag_block_cloud_edit($options); |
|
| 42 | + return tag_block_cloud_edit($options); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | function references_tag_block_top_show($options) |
| 46 | 46 | { |
| 47 | - require XOOPS_ROOT_PATH . '/modules/references/include/common.php'; |
|
| 48 | - if (!references_utils::tagModuleExists()) { |
|
| 49 | - return false; |
|
| 50 | - } |
|
| 51 | - require_once XOOPS_ROOT_PATH . '/modules/tag/blocks/block.php'; |
|
| 47 | + require XOOPS_ROOT_PATH . '/modules/references/include/common.php'; |
|
| 48 | + if (!references_utils::tagModuleExists()) { |
|
| 49 | + return false; |
|
| 50 | + } |
|
| 51 | + require_once XOOPS_ROOT_PATH . '/modules/tag/blocks/block.php'; |
|
| 52 | 52 | |
| 53 | - return tag_block_top_show($options, 'references'); |
|
| 53 | + return tag_block_top_show($options, 'references'); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | function references_tag_block_top_edit($options) |
| 57 | 57 | { |
| 58 | - require XOOPS_ROOT_PATH . '/modules/references/include/common.php'; |
|
| 59 | - if (!references_utils::tagModuleExists()) { |
|
| 60 | - return false; |
|
| 61 | - } |
|
| 62 | - require_once XOOPS_ROOT_PATH . '/modules/tag/blocks/block.php'; |
|
| 58 | + require XOOPS_ROOT_PATH . '/modules/references/include/common.php'; |
|
| 59 | + if (!references_utils::tagModuleExists()) { |
|
| 60 | + return false; |
|
| 61 | + } |
|
| 62 | + require_once XOOPS_ROOT_PATH . '/modules/tag/blocks/block.php'; |
|
| 63 | 63 | |
| 64 | - return tag_block_top_edit($options); |
|
| 64 | + return tag_block_top_edit($options); |
|
| 65 | 65 | } |
@@ -22,44 +22,44 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | function references_tag_block_cloud_show($options) |
| 24 | 24 | { |
| 25 | - require XOOPS_ROOT_PATH . '/modules/references/include/common.php'; |
|
| 25 | + require XOOPS_ROOT_PATH.'/modules/references/include/common.php'; |
|
| 26 | 26 | if (!references_utils::tagModuleExists()) { |
| 27 | 27 | return false; |
| 28 | 28 | } |
| 29 | - require_once XOOPS_ROOT_PATH . '/modules/tag/blocks/block.php'; |
|
| 29 | + require_once XOOPS_ROOT_PATH.'/modules/tag/blocks/block.php'; |
|
| 30 | 30 | |
| 31 | 31 | return tag_block_cloud_show($options, 'references'); |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | function references_tag_block_cloud_edit($options) |
| 35 | 35 | { |
| 36 | - require XOOPS_ROOT_PATH . '/modules/references/include/common.php'; |
|
| 36 | + require XOOPS_ROOT_PATH.'/modules/references/include/common.php'; |
|
| 37 | 37 | if (!references_utils::tagModuleExists()) { |
| 38 | 38 | return false; |
| 39 | 39 | } |
| 40 | - require_once XOOPS_ROOT_PATH . '/modules/tag/blocks/block.php'; |
|
| 40 | + require_once XOOPS_ROOT_PATH.'/modules/tag/blocks/block.php'; |
|
| 41 | 41 | |
| 42 | 42 | return tag_block_cloud_edit($options); |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | function references_tag_block_top_show($options) |
| 46 | 46 | { |
| 47 | - require XOOPS_ROOT_PATH . '/modules/references/include/common.php'; |
|
| 47 | + require XOOPS_ROOT_PATH.'/modules/references/include/common.php'; |
|
| 48 | 48 | if (!references_utils::tagModuleExists()) { |
| 49 | 49 | return false; |
| 50 | 50 | } |
| 51 | - require_once XOOPS_ROOT_PATH . '/modules/tag/blocks/block.php'; |
|
| 51 | + require_once XOOPS_ROOT_PATH.'/modules/tag/blocks/block.php'; |
|
| 52 | 52 | |
| 53 | 53 | return tag_block_top_show($options, 'references'); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | function references_tag_block_top_edit($options) |
| 57 | 57 | { |
| 58 | - require XOOPS_ROOT_PATH . '/modules/references/include/common.php'; |
|
| 58 | + require XOOPS_ROOT_PATH.'/modules/references/include/common.php'; |
|
| 59 | 59 | if (!references_utils::tagModuleExists()) { |
| 60 | 60 | return false; |
| 61 | 61 | } |
| 62 | - require_once XOOPS_ROOT_PATH . '/modules/tag/blocks/block.php'; |
|
| 62 | + require_once XOOPS_ROOT_PATH.'/modules/tag/blocks/block.php'; |
|
| 63 | 63 | |
| 64 | 64 | return tag_block_top_edit($options); |
| 65 | 65 | } |
@@ -26,28 +26,28 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | function b_references_random_news_show($options) |
| 28 | 28 | { |
| 29 | - global $xoopsConfig; |
|
| 30 | - require XOOPS_ROOT_PATH . '/modules/references/include/common.php'; |
|
| 31 | - $block = array(); |
|
| 32 | - $start = 0; |
|
| 33 | - $limit = (int)$options[0]; |
|
| 34 | - if ($limit > 0) { |
|
| 35 | - $items = array(); |
|
| 36 | - $h_references_articles->setCachingOptions(array('cacheDir' => REFERENCES_CACHE_PATH, 'caching' => false, 'lifeTime' => null, 'automaticSerialization' => true, 'fileNameProtection' => false)); |
|
| 37 | - $categories = array(); |
|
| 38 | - if (is_array($options) && count($options) > 1) { |
|
| 39 | - $categories = array_slice($options, 1); |
|
| 40 | - } |
|
| 41 | - $items = $h_references_articles->getRecentArticles($start, $limit, 'RAND(), NOW()', 'DESC', true, $categories); |
|
| 42 | - $h_references_articles->setCachingOptions(array('cacheDir' => REFERENCES_CACHE_PATH, 'caching' => true, 'lifeTime' => null, 'automaticSerialization' => true, 'fileNameProtection' => false)); |
|
| 43 | - if (count($items) > 0) { |
|
| 44 | - foreach ($items as $item) { |
|
| 45 | - $block['block_random_news'][] = $item->toArray(); |
|
| 46 | - } |
|
| 47 | - } |
|
| 48 | - } |
|
| 29 | + global $xoopsConfig; |
|
| 30 | + require XOOPS_ROOT_PATH . '/modules/references/include/common.php'; |
|
| 31 | + $block = array(); |
|
| 32 | + $start = 0; |
|
| 33 | + $limit = (int)$options[0]; |
|
| 34 | + if ($limit > 0) { |
|
| 35 | + $items = array(); |
|
| 36 | + $h_references_articles->setCachingOptions(array('cacheDir' => REFERENCES_CACHE_PATH, 'caching' => false, 'lifeTime' => null, 'automaticSerialization' => true, 'fileNameProtection' => false)); |
|
| 37 | + $categories = array(); |
|
| 38 | + if (is_array($options) && count($options) > 1) { |
|
| 39 | + $categories = array_slice($options, 1); |
|
| 40 | + } |
|
| 41 | + $items = $h_references_articles->getRecentArticles($start, $limit, 'RAND(), NOW()', 'DESC', true, $categories); |
|
| 42 | + $h_references_articles->setCachingOptions(array('cacheDir' => REFERENCES_CACHE_PATH, 'caching' => true, 'lifeTime' => null, 'automaticSerialization' => true, 'fileNameProtection' => false)); |
|
| 43 | + if (count($items) > 0) { |
|
| 44 | + foreach ($items as $item) { |
|
| 45 | + $block['block_random_news'][] = $item->toArray(); |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - return $block; |
|
| 50 | + return $block; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -58,26 +58,26 @@ discard block |
||
| 58 | 58 | */ |
| 59 | 59 | function b_references_random_news_edit($options) |
| 60 | 60 | { |
| 61 | - global $xoopsConfig; |
|
| 62 | - include XOOPS_ROOT_PATH . '/modules/references/include/common.php'; |
|
| 63 | - $handlers = references_handler::getInstance(); |
|
| 64 | - $categories = $handlers->h_references_categories->getListArray(); |
|
| 65 | - $form = ''; |
|
| 66 | - $form .= "<table border='0'>"; |
|
| 67 | - $form .= '<tr><td>' . _MB_REFERENCES_ITEMS_COUNT . "</td><td><input type='text' name='options[]' id='options' value='" . $options[0] . "' /></td></tr>\n"; |
|
| 68 | - $form .= '<tr><td>' . _MB_REFERENCES_CATEGORIES . "</td><td><select name='options[]' multiple='multiple'>"; |
|
| 69 | - $size = count($options); |
|
| 70 | - foreach ($categories as $Idcategory => $categoryName) { |
|
| 71 | - $sel = ''; |
|
| 72 | - for ($i = 1; $i < $size; ++$i) { |
|
| 73 | - if ($options[$i] == $Idcategory) { |
|
| 74 | - $sel = " selected='selected'"; |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - $form .= "<option value='$Idcategory' $sel>$categoryName</option>"; |
|
| 78 | - } |
|
| 79 | - $form .= "</select></td></tr>\n"; |
|
| 80 | - $form .= '</table>'; |
|
| 61 | + global $xoopsConfig; |
|
| 62 | + include XOOPS_ROOT_PATH . '/modules/references/include/common.php'; |
|
| 63 | + $handlers = references_handler::getInstance(); |
|
| 64 | + $categories = $handlers->h_references_categories->getListArray(); |
|
| 65 | + $form = ''; |
|
| 66 | + $form .= "<table border='0'>"; |
|
| 67 | + $form .= '<tr><td>' . _MB_REFERENCES_ITEMS_COUNT . "</td><td><input type='text' name='options[]' id='options' value='" . $options[0] . "' /></td></tr>\n"; |
|
| 68 | + $form .= '<tr><td>' . _MB_REFERENCES_CATEGORIES . "</td><td><select name='options[]' multiple='multiple'>"; |
|
| 69 | + $size = count($options); |
|
| 70 | + foreach ($categories as $Idcategory => $categoryName) { |
|
| 71 | + $sel = ''; |
|
| 72 | + for ($i = 1; $i < $size; ++$i) { |
|
| 73 | + if ($options[$i] == $Idcategory) { |
|
| 74 | + $sel = " selected='selected'"; |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + $form .= "<option value='$Idcategory' $sel>$categoryName</option>"; |
|
| 78 | + } |
|
| 79 | + $form .= "</select></td></tr>\n"; |
|
| 80 | + $form .= '</table>'; |
|
| 81 | 81 | |
| 82 | - return $form; |
|
| 82 | + return $form; |
|
| 83 | 83 | } |
@@ -27,10 +27,10 @@ discard block |
||
| 27 | 27 | function b_references_random_news_show($options) |
| 28 | 28 | { |
| 29 | 29 | global $xoopsConfig; |
| 30 | - require XOOPS_ROOT_PATH . '/modules/references/include/common.php'; |
|
| 30 | + require XOOPS_ROOT_PATH.'/modules/references/include/common.php'; |
|
| 31 | 31 | $block = array(); |
| 32 | 32 | $start = 0; |
| 33 | - $limit = (int)$options[0]; |
|
| 33 | + $limit = (int) $options[0]; |
|
| 34 | 34 | if ($limit > 0) { |
| 35 | 35 | $items = array(); |
| 36 | 36 | $h_references_articles->setCachingOptions(array('cacheDir' => REFERENCES_CACHE_PATH, 'caching' => false, 'lifeTime' => null, 'automaticSerialization' => true, 'fileNameProtection' => false)); |
@@ -59,13 +59,13 @@ discard block |
||
| 59 | 59 | function b_references_random_news_edit($options) |
| 60 | 60 | { |
| 61 | 61 | global $xoopsConfig; |
| 62 | - include XOOPS_ROOT_PATH . '/modules/references/include/common.php'; |
|
| 62 | + include XOOPS_ROOT_PATH.'/modules/references/include/common.php'; |
|
| 63 | 63 | $handlers = references_handler::getInstance(); |
| 64 | 64 | $categories = $handlers->h_references_categories->getListArray(); |
| 65 | 65 | $form = ''; |
| 66 | 66 | $form .= "<table border='0'>"; |
| 67 | - $form .= '<tr><td>' . _MB_REFERENCES_ITEMS_COUNT . "</td><td><input type='text' name='options[]' id='options' value='" . $options[0] . "' /></td></tr>\n"; |
|
| 68 | - $form .= '<tr><td>' . _MB_REFERENCES_CATEGORIES . "</td><td><select name='options[]' multiple='multiple'>"; |
|
| 67 | + $form .= '<tr><td>'._MB_REFERENCES_ITEMS_COUNT."</td><td><input type='text' name='options[]' id='options' value='".$options[0]."' /></td></tr>\n"; |
|
| 68 | + $form .= '<tr><td>'._MB_REFERENCES_CATEGORIES."</td><td><select name='options[]' multiple='multiple'>"; |
|
| 69 | 69 | $size = count($options); |
| 70 | 70 | foreach ($categories as $Idcategory => $categoryName) { |
| 71 | 71 | $sel = ''; |
@@ -28,11 +28,11 @@ discard block |
||
| 28 | 28 | @$xoopsLogger->activated = false; |
| 29 | 29 | |
| 30 | 30 | if (!references_utils::getModuleOption('use_rss')) { |
| 31 | - exit(_ERRORS); |
|
| 31 | + exit(_ERRORS); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | if (function_exists('mb_http_output')) { |
| 35 | - mb_http_output('pass'); |
|
| 35 | + mb_http_output('pass'); |
|
| 36 | 36 | } |
| 37 | 37 | $charset = 'utf-8'; |
| 38 | 38 | header('Content-Type:text/xml; charset=' . $charset); |
@@ -42,52 +42,52 @@ discard block |
||
| 42 | 42 | $tpl->xoops_setCacheTime(references_utils::getModuleOption('rss_cache_time')); // Temps de cache en secondes |
| 43 | 43 | $uid = references_utils::getCurrentUserID(); |
| 44 | 44 | if (!$tpl->is_cached('db:references_rss.tpl', $uid)) { |
| 45 | - $categoryTitle = ''; |
|
| 46 | - global $xoopsConfig; |
|
| 47 | - $sitename = htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES); |
|
| 48 | - $email = $xoopsConfig['adminmail']; |
|
| 49 | - $slogan = htmlspecialchars($xoopsConfig['slogan'], ENT_QUOTES); |
|
| 45 | + $categoryTitle = ''; |
|
| 46 | + global $xoopsConfig; |
|
| 47 | + $sitename = htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES); |
|
| 48 | + $email = $xoopsConfig['adminmail']; |
|
| 49 | + $slogan = htmlspecialchars($xoopsConfig['slogan'], ENT_QUOTES); |
|
| 50 | 50 | |
| 51 | - $tpl->assign('charset', $charset); |
|
| 52 | - $tpl->assign('channel_title', xoops_utf8_encode($sitename)); |
|
| 53 | - $tpl->assign('channel_link', XOOPS_URL . '/'); |
|
| 54 | - $tpl->assign('channel_desc', xoops_utf8_encode($slogan)); |
|
| 55 | - $tpl->assign('channel_lastbuild', formatTimestamp(time(), 'rss')); |
|
| 56 | - $tpl->assign('channel_webmaster', xoops_utf8_encode($email)); |
|
| 57 | - $tpl->assign('channel_editor', xoops_utf8_encode($email)); |
|
| 58 | - $tpl->assign('channel_category', xoops_utf8_encode($categoryTitle)); |
|
| 59 | - $tpl->assign('channel_generator', xoops_utf8_encode(references_utils::getModuleName())); |
|
| 60 | - $tpl->assign('channel_language', _LANGCODE); |
|
| 61 | - $tpl->assign('image_url', XOOPS_URL . '/assets/images/logo.gif'); |
|
| 62 | - $dimention = getimagesize(XOOPS_ROOT_PATH . '/assets/images/logo.gif'); |
|
| 63 | - if (empty($dimention[0])) { |
|
| 64 | - $width = 88; |
|
| 65 | - } else { |
|
| 66 | - $width = ($dimention[0] > 144) ? 144 : $dimention[0]; |
|
| 67 | - } |
|
| 68 | - if (empty($dimention[1])) { |
|
| 69 | - $height = 31; |
|
| 70 | - } else { |
|
| 71 | - $height = ($dimention[1] > 400) ? 400 : $dimention[1]; |
|
| 72 | - } |
|
| 73 | - $tpl->assign('image_width', $width); |
|
| 74 | - $tpl->assign('image_height', $height); |
|
| 75 | - $start = 0; |
|
| 76 | - $limit = references_utils::getModuleOption('nb_perpage'); |
|
| 77 | - $items = array(); |
|
| 51 | + $tpl->assign('charset', $charset); |
|
| 52 | + $tpl->assign('channel_title', xoops_utf8_encode($sitename)); |
|
| 53 | + $tpl->assign('channel_link', XOOPS_URL . '/'); |
|
| 54 | + $tpl->assign('channel_desc', xoops_utf8_encode($slogan)); |
|
| 55 | + $tpl->assign('channel_lastbuild', formatTimestamp(time(), 'rss')); |
|
| 56 | + $tpl->assign('channel_webmaster', xoops_utf8_encode($email)); |
|
| 57 | + $tpl->assign('channel_editor', xoops_utf8_encode($email)); |
|
| 58 | + $tpl->assign('channel_category', xoops_utf8_encode($categoryTitle)); |
|
| 59 | + $tpl->assign('channel_generator', xoops_utf8_encode(references_utils::getModuleName())); |
|
| 60 | + $tpl->assign('channel_language', _LANGCODE); |
|
| 61 | + $tpl->assign('image_url', XOOPS_URL . '/assets/images/logo.gif'); |
|
| 62 | + $dimention = getimagesize(XOOPS_ROOT_PATH . '/assets/images/logo.gif'); |
|
| 63 | + if (empty($dimention[0])) { |
|
| 64 | + $width = 88; |
|
| 65 | + } else { |
|
| 66 | + $width = ($dimention[0] > 144) ? 144 : $dimention[0]; |
|
| 67 | + } |
|
| 68 | + if (empty($dimention[1])) { |
|
| 69 | + $height = 31; |
|
| 70 | + } else { |
|
| 71 | + $height = ($dimention[1] > 400) ? 400 : $dimention[1]; |
|
| 72 | + } |
|
| 73 | + $tpl->assign('image_width', $width); |
|
| 74 | + $tpl->assign('image_height', $height); |
|
| 75 | + $start = 0; |
|
| 76 | + $limit = references_utils::getModuleOption('nb_perpage'); |
|
| 77 | + $items = array(); |
|
| 78 | 78 | |
| 79 | - $items = $h_references_articles->getRecentArticles($start, $limit); |
|
| 80 | - foreach ($items as $item) { |
|
| 81 | - $titre = htmlspecialchars($item->getVar('article_title', 'n'), ENT_QUOTES); |
|
| 82 | - $description = htmlspecialchars($item->getVar('article_text'), ENT_QUOTES); |
|
| 83 | - $link = REFERENCES_URL; |
|
| 84 | - $tpl->append('items', array( |
|
| 85 | - 'title' => xoops_utf8_encode($titre), |
|
| 86 | - 'link' => $link, |
|
| 87 | - 'guid' => $link, |
|
| 88 | - 'pubdate' => formatTimestamp($item->getVar('article_timestamp'), 'rss'), |
|
| 89 | - 'description' => xoops_utf8_encode($description) |
|
| 90 | - )); |
|
| 91 | - } |
|
| 79 | + $items = $h_references_articles->getRecentArticles($start, $limit); |
|
| 80 | + foreach ($items as $item) { |
|
| 81 | + $titre = htmlspecialchars($item->getVar('article_title', 'n'), ENT_QUOTES); |
|
| 82 | + $description = htmlspecialchars($item->getVar('article_text'), ENT_QUOTES); |
|
| 83 | + $link = REFERENCES_URL; |
|
| 84 | + $tpl->append('items', array( |
|
| 85 | + 'title' => xoops_utf8_encode($titre), |
|
| 86 | + 'link' => $link, |
|
| 87 | + 'guid' => $link, |
|
| 88 | + 'pubdate' => formatTimestamp($item->getVar('article_timestamp'), 'rss'), |
|
| 89 | + 'description' => xoops_utf8_encode($description) |
|
| 90 | + )); |
|
| 91 | + } |
|
| 92 | 92 | } |
| 93 | 93 | $tpl->display('db:references_rss.tpl', $uid); |
@@ -22,8 +22,8 @@ discard block |
||
| 22 | 22 | /** |
| 23 | 23 | * Flux RSS |
| 24 | 24 | */ |
| 25 | -require __DIR__ . '/header.php'; |
|
| 26 | -require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 25 | +require __DIR__.'/header.php'; |
|
| 26 | +require_once XOOPS_ROOT_PATH.'/class/template.php'; |
|
| 27 | 27 | error_reporting(0); |
| 28 | 28 | @$xoopsLogger->activated = false; |
| 29 | 29 | |
@@ -35,11 +35,11 @@ discard block |
||
| 35 | 35 | mb_http_output('pass'); |
| 36 | 36 | } |
| 37 | 37 | $charset = 'utf-8'; |
| 38 | -header('Content-Type:text/xml; charset=' . $charset); |
|
| 38 | +header('Content-Type:text/xml; charset='.$charset); |
|
| 39 | 39 | |
| 40 | 40 | $tpl = new XoopsTpl(); |
| 41 | -$tpl->xoops_setCaching(2); // 1 = Cache global, 2 = Cache individuel (par template) |
|
| 42 | -$tpl->xoops_setCacheTime(references_utils::getModuleOption('rss_cache_time')); // Temps de cache en secondes |
|
| 41 | +$tpl->xoops_setCaching(2); // 1 = Cache global, 2 = Cache individuel (par template) |
|
| 42 | +$tpl->xoops_setCacheTime(references_utils::getModuleOption('rss_cache_time')); // Temps de cache en secondes |
|
| 43 | 43 | $uid = references_utils::getCurrentUserID(); |
| 44 | 44 | if (!$tpl->is_cached('db:references_rss.tpl', $uid)) { |
| 45 | 45 | $categoryTitle = ''; |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | $tpl->assign('charset', $charset); |
| 52 | 52 | $tpl->assign('channel_title', xoops_utf8_encode($sitename)); |
| 53 | - $tpl->assign('channel_link', XOOPS_URL . '/'); |
|
| 53 | + $tpl->assign('channel_link', XOOPS_URL.'/'); |
|
| 54 | 54 | $tpl->assign('channel_desc', xoops_utf8_encode($slogan)); |
| 55 | 55 | $tpl->assign('channel_lastbuild', formatTimestamp(time(), 'rss')); |
| 56 | 56 | $tpl->assign('channel_webmaster', xoops_utf8_encode($email)); |
@@ -58,8 +58,8 @@ discard block |
||
| 58 | 58 | $tpl->assign('channel_category', xoops_utf8_encode($categoryTitle)); |
| 59 | 59 | $tpl->assign('channel_generator', xoops_utf8_encode(references_utils::getModuleName())); |
| 60 | 60 | $tpl->assign('channel_language', _LANGCODE); |
| 61 | - $tpl->assign('image_url', XOOPS_URL . '/assets/images/logo.gif'); |
|
| 62 | - $dimention = getimagesize(XOOPS_ROOT_PATH . '/assets/images/logo.gif'); |
|
| 61 | + $tpl->assign('image_url', XOOPS_URL.'/assets/images/logo.gif'); |
|
| 62 | + $dimention = getimagesize(XOOPS_ROOT_PATH.'/assets/images/logo.gif'); |
|
| 63 | 63 | if (empty($dimention[0])) { |
| 64 | 64 | $width = 88; |
| 65 | 65 | } else { |
@@ -28,840 +28,840 @@ |
||
| 28 | 28 | class references_Cache_Lite |
| 29 | 29 | { |
| 30 | 30 | |
| 31 | - // --- Private properties --- |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Directory where to put the cache files |
|
| 35 | - * (make sure to add a trailing slash) |
|
| 36 | - * |
|
| 37 | - * @var string $_cacheDir |
|
| 38 | - */ |
|
| 39 | - public $_cacheDir = '/tmp/'; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Enable / disable caching |
|
| 43 | - * |
|
| 44 | - * (can be very usefull for the debug of cached scripts) |
|
| 45 | - * |
|
| 46 | - * @var boolean $_caching |
|
| 47 | - */ |
|
| 48 | - public $_caching = true; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Cache lifetime (in seconds) |
|
| 52 | - * |
|
| 53 | - * If null, the cache is valid forever. |
|
| 54 | - * |
|
| 55 | - * @var int $_lifeTime |
|
| 56 | - */ |
|
| 57 | - public $_lifeTime = 3600; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Enable / disable fileLocking |
|
| 61 | - * |
|
| 62 | - * (can avoid cache corruption under bad circumstances) |
|
| 63 | - * |
|
| 64 | - * @var boolean $_fileLocking |
|
| 65 | - */ |
|
| 66 | - public $_fileLocking = true; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Timestamp of the last valid cache |
|
| 70 | - * |
|
| 71 | - * @var int $_refreshTime |
|
| 72 | - */ |
|
| 73 | - public $_refreshTime; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * File name (with path) |
|
| 77 | - * |
|
| 78 | - * @var string $_file |
|
| 79 | - */ |
|
| 80 | - public $_file; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * File name (without path) |
|
| 84 | - * |
|
| 85 | - * @var string $_fileName |
|
| 86 | - */ |
|
| 87 | - public $_fileName; |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Enable / disable write control (the cache is read just after writing to detect corrupt entries) |
|
| 91 | - * |
|
| 92 | - * Enable write control will lightly slow the cache writing but not the cache reading |
|
| 93 | - * Write control can detect some corrupt cache files but maybe it's not a perfect control |
|
| 94 | - * |
|
| 95 | - * @var boolean $_writeControl |
|
| 96 | - */ |
|
| 97 | - public $_writeControl = true; |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Enable / disable read control |
|
| 101 | - * |
|
| 102 | - * If enabled, a control key is embeded in cache file and this key is compared with the one |
|
| 103 | - * calculated after the reading. |
|
| 104 | - * |
|
| 105 | - * @var boolean $_writeControl |
|
| 106 | - */ |
|
| 107 | - public $_readControl = true; |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Type of read control (only if read control is enabled) |
|
| 111 | - * |
|
| 112 | - * Available values are : |
|
| 113 | - * 'md5' for a md5 hash control (best but slowest) |
|
| 114 | - * 'crc32' for a crc32 hash control (lightly less safe but faster, better choice) |
|
| 115 | - * 'strlen' for a length only test (fastest) |
|
| 116 | - * |
|
| 117 | - * @var boolean $_readControlType |
|
| 118 | - */ |
|
| 119 | - public $_readControlType = 'crc32'; |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Pear error mode (when raiseError is called) |
|
| 123 | - * |
|
| 124 | - * (see PEAR doc) |
|
| 125 | - * |
|
| 126 | - * @see setToDebug() |
|
| 127 | - * @var int $_pearErrorMode |
|
| 128 | - */ |
|
| 129 | - public $_pearErrorMode = REFERENCES_CACHE_LITE_ERROR_RETURN; |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Current cache id |
|
| 133 | - * |
|
| 134 | - * @var string $_id |
|
| 135 | - */ |
|
| 136 | - public $_id; |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Current cache group |
|
| 140 | - * |
|
| 141 | - * @var string $_group |
|
| 142 | - */ |
|
| 143 | - public $_group; |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Enable / Disable "Memory Caching" |
|
| 147 | - * |
|
| 148 | - * NB : There is no lifetime for memory caching ! |
|
| 149 | - * |
|
| 150 | - * @var boolean $_memoryCaching |
|
| 151 | - */ |
|
| 152 | - public $_memoryCaching = false; |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Enable / Disable "Only Memory Caching" |
|
| 156 | - * (be carefull, memory caching is "beta quality") |
|
| 157 | - * |
|
| 158 | - * @var boolean $_onlyMemoryCaching |
|
| 159 | - */ |
|
| 160 | - public $_onlyMemoryCaching = false; |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Memory caching array |
|
| 164 | - * |
|
| 165 | - * @var array $_memoryCachingArray |
|
| 166 | - */ |
|
| 167 | - public $_memoryCachingArray = array(); |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * Memory caching counter |
|
| 171 | - * |
|
| 172 | - * @var int $memoryCachingCounter |
|
| 173 | - */ |
|
| 174 | - public $_memoryCachingCounter = 0; |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Memory caching limit |
|
| 178 | - * |
|
| 179 | - * @var int $memoryCachingLimit |
|
| 180 | - */ |
|
| 181 | - public $_memoryCachingLimit = 1000; |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * File Name protection |
|
| 185 | - * |
|
| 186 | - * if set to true, you can use any cache id or group name |
|
| 187 | - * if set to false, it can be faster but cache ids and group names |
|
| 188 | - * will be used directly in cache file names so be carefull with |
|
| 189 | - * special characters... |
|
| 190 | - * |
|
| 191 | - * @var boolean $fileNameProtection |
|
| 192 | - */ |
|
| 193 | - public $_fileNameProtection = true; |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Enable / disable automatic serialization |
|
| 197 | - * |
|
| 198 | - * it can be used to save directly datas which aren't strings |
|
| 199 | - * (but it's slower) |
|
| 200 | - * |
|
| 201 | - * @var boolean $_serialize |
|
| 202 | - */ |
|
| 203 | - public $_automaticSerialization = false; |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * Disable / Tune the automatic cleaning process |
|
| 207 | - * |
|
| 208 | - * The automatic cleaning process destroy too old (for the given life time) |
|
| 209 | - * cache files when a new cache file is written. |
|
| 210 | - * 0 => no automatic cache cleaning |
|
| 211 | - * 1 => systematic cache cleaning |
|
| 212 | - * x (integer) > 1 => automatic cleaning randomly 1 times on x cache write |
|
| 213 | - * |
|
| 214 | - * @var int $_automaticCleaning |
|
| 215 | - */ |
|
| 216 | - public $_automaticCleaningFactor = 0; |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * Nested directory level |
|
| 220 | - * |
|
| 221 | - * Set the hashed directory structure level. 0 means "no hashed directory |
|
| 222 | - * structure", 1 means "one level of directory", 2 means "two levels"... |
|
| 223 | - * This option can speed up Cache_Lite only when you have many thousands of |
|
| 224 | - * cache file. Only specific benchs can help you to choose the perfect value |
|
| 225 | - * for you. Maybe, 1 or 2 is a good start. |
|
| 226 | - * |
|
| 227 | - * @var int $_hashedDirectoryLevel |
|
| 228 | - */ |
|
| 229 | - public $_hashedDirectoryLevel = 0; |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Umask for hashed directory structure |
|
| 233 | - * |
|
| 234 | - * @var int $_hashedDirectoryUmask |
|
| 235 | - */ |
|
| 236 | - public $_hashedDirectoryUmask = 0700; |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * API break for error handling in REFERENCES_CACHE_LITE_ERROR_RETURN mode |
|
| 240 | - * |
|
| 241 | - * In REFERENCES_CACHE_LITE_ERROR_RETURN mode, error handling was not good because |
|
| 242 | - * for example save() method always returned a boolean (a PEAR_Error object |
|
| 243 | - * would be better in REFERENCES_CACHE_LITE_ERROR_RETURN mode). To correct this without |
|
| 244 | - * breaking the API, this option (false by default) can change this handling. |
|
| 245 | - * |
|
| 246 | - * @var boolean |
|
| 247 | - */ |
|
| 248 | - public $_errorHandlingAPIBreak = false; |
|
| 249 | - |
|
| 250 | - // --- Public methods --- |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * Constructor |
|
| 254 | - * |
|
| 255 | - * $options is an assoc. Available options are : |
|
| 256 | - * $options = array( |
|
| 257 | - * 'cacheDir' => directory where to put the cache files (string) , |
|
| 258 | - * 'caching' => enable / disable caching (boolean) , |
|
| 259 | - * 'lifeTime' => cache lifetime in seconds (int) , |
|
| 260 | - * 'fileLocking' => enable / disable fileLocking (boolean) , |
|
| 261 | - * 'writeControl' => enable / disable write control (boolean) , |
|
| 262 | - * 'readControl' => enable / disable read control (boolean) , |
|
| 263 | - * 'readControlType' => type of read control 'crc32', 'md5', 'strlen' (string) , |
|
| 264 | - * 'pearErrorMode' => pear error mode (when raiseError is called) (cf PEAR doc) (int) , |
|
| 265 | - * 'memoryCaching' => enable / disable memory caching (boolean) , |
|
| 266 | - * 'onlyMemoryCaching' => enable / disable only memory caching (boolean) , |
|
| 267 | - * 'memoryCachingLimit' => max nbr of records to store into memory caching (int) , |
|
| 268 | - * 'fileNameProtection' => enable / disable automatic file name protection (boolean) , |
|
| 269 | - * 'automaticSerialization' => enable / disable automatic serialization (boolean) , |
|
| 270 | - * 'automaticCleaningFactor' => distable / tune automatic cleaning process (int) , |
|
| 271 | - * 'hashedDirectoryLevel' => level of the hashed directory system (int) , |
|
| 272 | - * 'hashedDirectoryUmask' => umask for hashed directory structure (int) , |
|
| 273 | - * 'errorHandlingAPIBreak' => API break for better error handling ? (boolean) |
|
| 274 | - * ); |
|
| 275 | - * |
|
| 276 | - * @param array $options options |
|
| 277 | - * @access public |
|
| 278 | - */ |
|
| 279 | - public function __construct($options = array(null)) |
|
| 280 | - { |
|
| 281 | - foreach ($options as $key => $value) { |
|
| 282 | - $this->setOption($key, $value); |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * Generic way to set a Cache_Lite option |
|
| 288 | - * |
|
| 289 | - * see Cache_Lite constructor for available options |
|
| 290 | - * |
|
| 291 | - * @var string $name name of the option |
|
| 292 | - * @var mixed $value value of the option |
|
| 293 | - * @access public |
|
| 294 | - */ |
|
| 295 | - public function setOption($name, $value) |
|
| 296 | - { |
|
| 297 | - $availableOptions = array( |
|
| 298 | - 'errorHandlingAPIBreak', |
|
| 299 | - 'hashedDirectoryUmask', |
|
| 300 | - 'hashedDirectoryLevel', |
|
| 301 | - 'automaticCleaningFactor', |
|
| 302 | - 'automaticSerialization', |
|
| 303 | - 'fileNameProtection', |
|
| 304 | - 'memoryCaching', |
|
| 305 | - 'onlyMemoryCaching', |
|
| 306 | - 'memoryCachingLimit', |
|
| 307 | - 'cacheDir', |
|
| 308 | - 'caching', |
|
| 309 | - 'lifeTime', |
|
| 310 | - 'fileLocking', |
|
| 311 | - 'writeControl', |
|
| 312 | - 'readControl', |
|
| 313 | - 'readControlType', |
|
| 314 | - 'pearErrorMode' |
|
| 315 | - ); |
|
| 316 | - if (in_array($name, $availableOptions)) { |
|
| 317 | - $property = '_' . $name; |
|
| 318 | - $this->$property = $value; |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * Test if a cache is available and (if yes) return it |
|
| 324 | - * |
|
| 325 | - * @param string $id cache id |
|
| 326 | - * @param string $group name of the cache group |
|
| 327 | - * @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested |
|
| 328 | - * @return string data of the cache (else : false) |
|
| 329 | - * @access public |
|
| 330 | - */ |
|
| 331 | - public function get($id, $group = 'default', $doNotTestCacheValidity = false) |
|
| 332 | - { |
|
| 333 | - $this->_id = $id; |
|
| 334 | - $this->_group = $group; |
|
| 335 | - $data = false; |
|
| 336 | - if ($this->_caching) { |
|
| 337 | - $this->_setRefreshTime(); |
|
| 338 | - $this->_setFileName($id, $group); |
|
| 339 | - clearstatcache(); |
|
| 340 | - if ($this->_memoryCaching) { |
|
| 341 | - if (isset($this->_memoryCachingArray[$this->_file])) { |
|
| 342 | - if ($this->_automaticSerialization) { |
|
| 343 | - return unserialize($this->_memoryCachingArray[$this->_file]); |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - return $this->_memoryCachingArray[$this->_file]; |
|
| 347 | - } |
|
| 348 | - if ($this->_onlyMemoryCaching) { |
|
| 349 | - return false; |
|
| 350 | - } |
|
| 351 | - } |
|
| 352 | - if ($doNotTestCacheValidity || is_null($this->_refreshTime)) { |
|
| 353 | - if (file_exists($this->_file)) { |
|
| 354 | - $data = $this->_read(); |
|
| 355 | - } |
|
| 356 | - } else { |
|
| 357 | - if (file_exists($this->_file) && (@filemtime($this->_file) > $this->_refreshTime)) { |
|
| 358 | - $data = $this->_read(); |
|
| 359 | - } |
|
| 360 | - } |
|
| 361 | - if ($data && $this->_memoryCaching) { |
|
| 362 | - $this->_memoryCacheAdd($data); |
|
| 363 | - } |
|
| 364 | - if ($this->_automaticSerialization && is_string($data)) { |
|
| 365 | - $data = unserialize($data); |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - return $data; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - return false; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * Save some data in a cache file |
|
| 376 | - * |
|
| 377 | - * @param string $data data to put in cache (can be another type than strings if automaticSerialization is on) |
|
| 378 | - * @param string $id cache id |
|
| 379 | - * @param string $group name of the cache group |
|
| 380 | - * @return boolean true if no problem (else : false or a PEAR_Error object) |
|
| 381 | - * @access public |
|
| 382 | - */ |
|
| 383 | - public function save($data, $id = null, $group = 'default') |
|
| 384 | - { |
|
| 385 | - if ($this->_caching) { |
|
| 386 | - if ($this->_automaticSerialization) { |
|
| 387 | - $data = serialize($data); |
|
| 388 | - } |
|
| 389 | - if (isset($id)) { |
|
| 390 | - $this->_setFileName($id, $group); |
|
| 391 | - } |
|
| 392 | - if ($this->_memoryCaching) { |
|
| 393 | - $this->_memoryCacheAdd($data); |
|
| 394 | - if ($this->_onlyMemoryCaching) { |
|
| 395 | - return true; |
|
| 396 | - } |
|
| 397 | - } |
|
| 398 | - if ($this->_automaticCleaningFactor > 0 && ($this->_automaticCleaningFactor == 1 || mt_rand(1, $this->_automaticCleaningFactor) == 1)) { |
|
| 399 | - $this->clean(false, 'old'); |
|
| 400 | - } |
|
| 401 | - if ($this->_writeControl) { |
|
| 402 | - $res = $this->_writeAndControl($data); |
|
| 403 | - if (is_bool($res)) { |
|
| 404 | - if ($res) { |
|
| 405 | - return true; |
|
| 406 | - } |
|
| 407 | - // if $res if false, we need to invalidate the cache |
|
| 408 | - @touch($this->_file, time() - 2 * abs($this->_lifeTime)); |
|
| 409 | - |
|
| 410 | - return false; |
|
| 411 | - } |
|
| 412 | - } else { |
|
| 413 | - $res = $this->_write($data); |
|
| 414 | - } |
|
| 415 | - if (is_object($res)) { |
|
| 416 | - // $res is a PEAR_Error object |
|
| 417 | - if (!$this->_errorHandlingAPIBreak) { |
|
| 418 | - return false; // we return false (old API) |
|
| 419 | - } |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - return $res; |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - return false; |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - /** |
|
| 429 | - * Remove a cache file |
|
| 430 | - * |
|
| 431 | - * @param string $id cache id |
|
| 432 | - * @param string $group name of the cache group |
|
| 433 | - * @param boolean $checkbeforeunlink check if file exists before removing it |
|
| 434 | - * @return boolean true if no problem |
|
| 435 | - * @access public |
|
| 436 | - */ |
|
| 437 | - public function remove($id, $group = 'default', $checkbeforeunlink = false) |
|
| 438 | - { |
|
| 439 | - $this->_setFileName($id, $group); |
|
| 440 | - if ($this->_memoryCaching) { |
|
| 441 | - if (isset($this->_memoryCachingArray[$this->_file])) { |
|
| 442 | - unset($this->_memoryCachingArray[$this->_file]); |
|
| 443 | - --$this->_memoryCachingCounter; |
|
| 444 | - } |
|
| 445 | - if ($this->_onlyMemoryCaching) { |
|
| 446 | - return true; |
|
| 447 | - } |
|
| 448 | - } |
|
| 449 | - if ($checkbeforeunlink) { |
|
| 450 | - if (!file_exists($this->_file)) { |
|
| 451 | - return true; |
|
| 452 | - } |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - return $this->_unlink($this->_file); |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * Clean the cache |
|
| 460 | - * |
|
| 461 | - * if no group is specified all cache files will be destroyed |
|
| 462 | - * else only cache files of the specified group will be destroyed |
|
| 463 | - * |
|
| 464 | - * @param bool|string $group name of the cache group |
|
| 465 | - * @param string $mode flush cache mode : 'old', 'ingroup', 'notingroup', |
|
| 466 | - * 'callback_myFunction' |
|
| 467 | - * @return bool true if no problem |
|
| 468 | - * @access public |
|
| 469 | - */ |
|
| 470 | - public function clean($group = false, $mode = 'ingroup') |
|
| 471 | - { |
|
| 472 | - return $this->_cleanDir($this->_cacheDir, $group, $mode); |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - /** |
|
| 476 | - * Set to debug mode |
|
| 477 | - * |
|
| 478 | - * When an error is found, the script will stop and the message will be displayed |
|
| 479 | - * (in debug mode only). |
|
| 480 | - * |
|
| 481 | - * @access public |
|
| 482 | - */ |
|
| 483 | - public function setToDebug() |
|
| 484 | - { |
|
| 485 | - $this->setOption('pearErrorMode', REFERENCES_CACHE_LITE_ERROR_DIE); |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - /** |
|
| 489 | - * Set a new life time |
|
| 490 | - * |
|
| 491 | - * @param int $newLifeTime new life time (in seconds) |
|
| 492 | - * @access public |
|
| 493 | - */ |
|
| 494 | - public function setLifeTime($newLifeTime) |
|
| 495 | - { |
|
| 496 | - $this->_lifeTime = $newLifeTime; |
|
| 497 | - $this->_setRefreshTime(); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - /** |
|
| 501 | - * Save the state of the caching memory array into a cache file cache |
|
| 502 | - * |
|
| 503 | - * @param string $id cache id |
|
| 504 | - * @param string $group name of the cache group |
|
| 505 | - * @access public |
|
| 506 | - */ |
|
| 507 | - public function saveMemoryCachingState($id, $group = 'default') |
|
| 508 | - { |
|
| 509 | - if ($this->_caching) { |
|
| 510 | - $array = array( |
|
| 511 | - 'counter' => $this->_memoryCachingCounter, |
|
| 512 | - 'array' => $this->_memoryCachingArray |
|
| 513 | - ); |
|
| 514 | - $data = serialize($array); |
|
| 515 | - $this->save($data, $id, $group); |
|
| 516 | - } |
|
| 517 | - } |
|
| 518 | - |
|
| 519 | - /** |
|
| 520 | - * Load the state of the caching memory array from a given cache file cache |
|
| 521 | - * |
|
| 522 | - * @param string $id cache id |
|
| 523 | - * @param string $group name of the cache group |
|
| 524 | - * @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested |
|
| 525 | - * @access public |
|
| 526 | - */ |
|
| 527 | - public function getMemoryCachingState($id, $group = 'default', $doNotTestCacheValidity = false) |
|
| 528 | - { |
|
| 529 | - if ($this->_caching) { |
|
| 530 | - if ($data = $this->get($id, $group, $doNotTestCacheValidity)) { |
|
| 531 | - $array = unserialize($data); |
|
| 532 | - $this->_memoryCachingCounter = $array['counter']; |
|
| 533 | - $this->_memoryCachingArray = $array['array']; |
|
| 534 | - } |
|
| 535 | - } |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - /** |
|
| 539 | - * Return the cache last modification time |
|
| 540 | - * |
|
| 541 | - * BE CAREFUL : THIS METHOD IS FOR HACKING ONLY ! |
|
| 542 | - * |
|
| 543 | - * @return int last modification time |
|
| 544 | - */ |
|
| 545 | - public function lastModified() |
|
| 546 | - { |
|
| 547 | - return @filemtime($this->_file); |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - /** |
|
| 551 | - * Trigger a PEAR error |
|
| 552 | - * |
|
| 553 | - * To improve performances, the PEAR.php file is included dynamically. |
|
| 554 | - * The file is so included only when an error is triggered. So, in most |
|
| 555 | - * cases, the file isn't included and perfs are much better. |
|
| 556 | - * |
|
| 557 | - * @param string $msg error message |
|
| 558 | - * @param int $code error code |
|
| 559 | - * @access public |
|
| 560 | - * @return object |
|
| 561 | - */ |
|
| 562 | - public function raiseError($msg, $code) |
|
| 563 | - { |
|
| 564 | - include_once('PEAR.php'); |
|
| 565 | - |
|
| 566 | - return references_PEAR::raiseError($msg, $code, $this->_pearErrorMode); |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - /** |
|
| 570 | - * Extend the life of a valid cache file |
|
| 571 | - * |
|
| 572 | - * see http://pear.php.net/bugs/bug.php?id=6681 |
|
| 573 | - * |
|
| 574 | - * @access public |
|
| 575 | - */ |
|
| 576 | - public function extendLife() |
|
| 577 | - { |
|
| 578 | - @touch($this->_file); |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - // --- Private methods --- |
|
| 582 | - |
|
| 583 | - /** |
|
| 584 | - * Compute & set the refresh time |
|
| 585 | - * |
|
| 586 | - * @access private |
|
| 587 | - */ |
|
| 588 | - public function _setRefreshTime() |
|
| 589 | - { |
|
| 590 | - if (is_null($this->_lifeTime)) { |
|
| 591 | - $this->_refreshTime = null; |
|
| 592 | - } else { |
|
| 593 | - $this->_refreshTime = time() - $this->_lifeTime; |
|
| 594 | - } |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - /** |
|
| 598 | - * Remove a file |
|
| 599 | - * |
|
| 600 | - * @param string $file complete file path and name |
|
| 601 | - * @return boolean true if no problem |
|
| 602 | - * @access private |
|
| 603 | - */ |
|
| 604 | - public function _unlink($file) |
|
| 605 | - { |
|
| 606 | - if (!@unlink($file)) { |
|
| 607 | - return $this->raiseError('Cache_Lite : Unable to remove cache !', -3); |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - return true; |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - /** |
|
| 614 | - * Recursive function for cleaning cache file in the given directory |
|
| 615 | - * |
|
| 616 | - * @param string $dir directory complete path (with a trailing slash) |
|
| 617 | - * @param bool|string $group name of the cache group |
|
| 618 | - * @param string $mode flush cache mode : 'old', 'ingroup', 'notingroup', |
|
| 619 | - * 'callback_myFunction' |
|
| 620 | - * @return bool true if no problem |
|
| 621 | - * @access private |
|
| 622 | - */ |
|
| 623 | - public function _cleanDir($dir, $group = false, $mode = 'ingroup') |
|
| 624 | - { |
|
| 625 | - if ($this->_fileNameProtection) { |
|
| 626 | - $motif = $group ? 'cache_' . md5($group) . '_' : 'cache_'; |
|
| 627 | - } else { |
|
| 628 | - $motif = $group ? 'cache_' . $group . '_' : 'cache_'; |
|
| 629 | - } |
|
| 630 | - if ($this->_memoryCaching) { |
|
| 631 | - foreach ($this->_memoryCachingArray as $key => $v) { |
|
| 632 | - if (strpos($key, $motif) !== false) { |
|
| 633 | - unset($this->_memoryCachingArray[$key]); |
|
| 634 | - --$this->_memoryCachingCounter; |
|
| 635 | - } |
|
| 636 | - } |
|
| 637 | - if ($this->_onlyMemoryCaching) { |
|
| 638 | - return true; |
|
| 639 | - } |
|
| 640 | - } |
|
| 641 | - if (!($dh = opendir($dir))) { |
|
| 642 | - return $this->raiseError('Cache_Lite : Unable to open cache directory !', -4); |
|
| 643 | - } |
|
| 644 | - $result = true; |
|
| 645 | - while ($file = readdir($dh)) { |
|
| 646 | - if (($file !== '.') && ($file !== '..')) { |
|
| 647 | - if (substr($file, 0, 6) === 'cache_') { |
|
| 648 | - $file2 = $dir . $file; |
|
| 649 | - if (is_file($file2)) { |
|
| 650 | - switch (substr($mode, 0, 9)) { |
|
| 651 | - case 'old': |
|
| 652 | - // files older than lifeTime get deleted from cache |
|
| 653 | - if (!is_null($this->_lifeTime)) { |
|
| 654 | - if ((time() - @filemtime($file2)) > $this->_lifeTime) { |
|
| 655 | - $result = ($result and $this->_unlink($file2)); |
|
| 656 | - } |
|
| 657 | - } |
|
| 658 | - break; |
|
| 659 | - case 'notingrou': |
|
| 660 | - if (strpos($file2, $motif) === false) { |
|
| 661 | - $result = ($result and $this->_unlink($file2)); |
|
| 662 | - } |
|
| 663 | - break; |
|
| 664 | - case 'callback_': |
|
| 665 | - $func = substr($mode, 9, strlen($mode) - 9); |
|
| 666 | - if ($func($file2, $group)) { |
|
| 667 | - $result = ($result and $this->_unlink($file2)); |
|
| 668 | - } |
|
| 669 | - break; |
|
| 670 | - case 'ingroup': |
|
| 671 | - default: |
|
| 672 | - if (strpos($file2, $motif) !== false) { |
|
| 673 | - $result = ($result and $this->_unlink($file2)); |
|
| 674 | - } |
|
| 675 | - break; |
|
| 676 | - } |
|
| 677 | - } |
|
| 678 | - if (is_dir($file2) and ($this->_hashedDirectoryLevel > 0)) { |
|
| 679 | - $result = ($result and $this->_cleanDir($file2 . '/', $group, $mode)); |
|
| 680 | - } |
|
| 681 | - } |
|
| 682 | - } |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - return $result; |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - /** |
|
| 689 | - * Add some date in the memory caching array |
|
| 690 | - * |
|
| 691 | - * @param string $data data to cache |
|
| 692 | - * @access private |
|
| 693 | - */ |
|
| 694 | - public function _memoryCacheAdd($data) |
|
| 695 | - { |
|
| 696 | - $this->_memoryCachingArray[$this->_file] = $data; |
|
| 697 | - if ($this->_memoryCachingCounter >= $this->_memoryCachingLimit) { |
|
| 698 | - list($key,) = each($this->_memoryCachingArray); |
|
| 699 | - unset($this->_memoryCachingArray[$key]); |
|
| 700 | - } else { |
|
| 701 | - ++$this->_memoryCachingCounter; |
|
| 702 | - } |
|
| 703 | - } |
|
| 704 | - |
|
| 705 | - /** |
|
| 706 | - * Make a file name (with path) |
|
| 707 | - * |
|
| 708 | - * @param string $id cache id |
|
| 709 | - * @param string $group name of the group |
|
| 710 | - * @access private |
|
| 711 | - */ |
|
| 712 | - public function _setFileName($id, $group) |
|
| 713 | - { |
|
| 714 | - if ($this->_fileNameProtection) { |
|
| 715 | - $suffix = 'cache_' . md5($group) . '_' . md5($id); |
|
| 716 | - } else { |
|
| 717 | - $suffix = 'cache_' . $group . '_' . $id; |
|
| 718 | - } |
|
| 719 | - $root = $this->_cacheDir; |
|
| 720 | - if ($this->_hashedDirectoryLevel > 0) { |
|
| 721 | - $hash = md5($suffix); |
|
| 722 | - for ($i = 0; $i < $this->_hashedDirectoryLevel; ++$i) { |
|
| 723 | - $root = $root . 'cache_' . substr($hash, 0, $i + 1) . '/'; |
|
| 724 | - } |
|
| 725 | - } |
|
| 726 | - $this->_fileName = $suffix; |
|
| 727 | - $this->_file = $root . $suffix; |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - /** |
|
| 731 | - * Read the cache file and return the content |
|
| 732 | - * |
|
| 733 | - * @return string content of the cache file (else : false or a PEAR_Error object) |
|
| 734 | - * @access private |
|
| 735 | - */ |
|
| 736 | - public function _read() |
|
| 737 | - { |
|
| 738 | - $fp = @fopen($this->_file, 'rb'); |
|
| 739 | - if ($this->_fileLocking) { |
|
| 740 | - @flock($fp, LOCK_SH); |
|
| 741 | - } |
|
| 742 | - if ($fp) { |
|
| 743 | - clearstatcache(); |
|
| 744 | - $length = @filesize($this->_file); |
|
| 745 | - // $mqr = get_magic_quotes_runtime(); |
|
| 746 | - // @set_magic_quotes_runtime(0); |
|
| 747 | - if ($this->_readControl) { |
|
| 748 | - $hashControl = @fread($fp, 32); |
|
| 749 | - $length = $length - 32; |
|
| 750 | - } |
|
| 751 | - if ($length) { |
|
| 752 | - $data = @fread($fp, $length); |
|
| 753 | - } else { |
|
| 754 | - $data = ''; |
|
| 755 | - } |
|
| 756 | - // @set_magic_quotes_runtime($mqr); |
|
| 757 | - if ($this->_fileLocking) { |
|
| 758 | - @flock($fp, LOCK_UN); |
|
| 759 | - } |
|
| 760 | - @fclose($fp); |
|
| 761 | - if ($this->_readControl) { |
|
| 762 | - $hashData = $this->_hash($data, $this->_readControlType); |
|
| 763 | - if ($hashData != $hashControl) { |
|
| 764 | - if (!is_null($this->_lifeTime)) { |
|
| 765 | - @touch($this->_file, time() - 2 * abs($this->_lifeTime)); |
|
| 766 | - } else { |
|
| 767 | - @unlink($this->_file); |
|
| 768 | - } |
|
| 769 | - |
|
| 770 | - return false; |
|
| 771 | - } |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - return $data; |
|
| 775 | - } |
|
| 776 | - |
|
| 777 | - return $this->raiseError('Cache_Lite : Unable to read cache !', -2); |
|
| 778 | - } |
|
| 779 | - |
|
| 780 | - /** |
|
| 781 | - * Write the given data in the cache file |
|
| 782 | - * |
|
| 783 | - * @param string $data data to put in cache |
|
| 784 | - * @return boolean true if ok (a PEAR_Error object else) |
|
| 785 | - * @access private |
|
| 786 | - */ |
|
| 787 | - public function _write($data) |
|
| 788 | - { |
|
| 789 | - if ($this->_hashedDirectoryLevel > 0) { |
|
| 790 | - $hash = md5($this->_fileName); |
|
| 791 | - $root = $this->_cacheDir; |
|
| 792 | - for ($i = 0; $i < $this->_hashedDirectoryLevel; ++$i) { |
|
| 793 | - $root = $root . 'cache_' . substr($hash, 0, $i + 1) . '/'; |
|
| 794 | - if (!(@is_dir($root))) { |
|
| 795 | - @mkdir($root, $this->_hashedDirectoryUmask); |
|
| 796 | - } |
|
| 797 | - } |
|
| 798 | - } |
|
| 799 | - $fp = @fopen($this->_file, 'wb'); |
|
| 800 | - if ($fp) { |
|
| 801 | - if ($this->_fileLocking) { |
|
| 802 | - @flock($fp, LOCK_EX); |
|
| 803 | - } |
|
| 804 | - if ($this->_readControl) { |
|
| 805 | - @fwrite($fp, $this->_hash($data, $this->_readControlType), 32); |
|
| 806 | - } |
|
| 807 | - // $mqr = get_magic_quotes_runtime(); |
|
| 808 | - // @set_magic_quotes_runtime(0); |
|
| 809 | - @fwrite($fp, $data); |
|
| 810 | - // @set_magic_quotes_runtime($mqr); |
|
| 811 | - if ($this->_fileLocking) { |
|
| 812 | - @flock($fp, LOCK_UN); |
|
| 813 | - } |
|
| 814 | - @fclose($fp); |
|
| 815 | - |
|
| 816 | - return true; |
|
| 817 | - } |
|
| 818 | - |
|
| 819 | - return $this->raiseError('Cache_Lite : Unable to write cache file : ' . $this->_file, -1); |
|
| 820 | - } |
|
| 821 | - |
|
| 822 | - /** |
|
| 823 | - * Write the given data in the cache file and control it just after to avoir corrupted cache entries |
|
| 824 | - * |
|
| 825 | - * @param string $data data to put in cache |
|
| 826 | - * @return boolean true if the test is ok (else : false or a PEAR_Error object) |
|
| 827 | - * @access private |
|
| 828 | - */ |
|
| 829 | - public function _writeAndControl($data) |
|
| 830 | - { |
|
| 831 | - $result = $this->_write($data); |
|
| 832 | - if (is_object($result)) { |
|
| 833 | - return $result; # We return the PEAR_Error object |
|
| 834 | - } |
|
| 835 | - $dataRead = $this->_read(); |
|
| 836 | - if (is_object($dataRead)) { |
|
| 837 | - return $dataRead; # We return the PEAR_Error object |
|
| 838 | - } |
|
| 839 | - if (is_bool($dataRead) && (!$dataRead)) { |
|
| 840 | - return false; |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - return ($dataRead == $data); |
|
| 844 | - } |
|
| 845 | - |
|
| 846 | - /** |
|
| 847 | - * Make a control key with the string containing datas |
|
| 848 | - * |
|
| 849 | - * @param string $data data |
|
| 850 | - * @param string $controlType type of control 'md5', 'crc32' or 'strlen' |
|
| 851 | - * @return string control key |
|
| 852 | - * @access private |
|
| 853 | - */ |
|
| 854 | - public function _hash($data, $controlType) |
|
| 855 | - { |
|
| 856 | - switch ($controlType) { |
|
| 857 | - case 'md5': |
|
| 858 | - return md5($data); |
|
| 859 | - case 'crc32': |
|
| 860 | - return sprintf('% 32d', crc32($data)); |
|
| 861 | - case 'strlen': |
|
| 862 | - return sprintf('% 32d', strlen($data)); |
|
| 863 | - default: |
|
| 864 | - return $this->raiseError('Unknown controlType ! (available values are only \'md5\', \'crc32\', \'strlen\')', -5); |
|
| 865 | - } |
|
| 866 | - } |
|
| 31 | + // --- Private properties --- |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Directory where to put the cache files |
|
| 35 | + * (make sure to add a trailing slash) |
|
| 36 | + * |
|
| 37 | + * @var string $_cacheDir |
|
| 38 | + */ |
|
| 39 | + public $_cacheDir = '/tmp/'; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Enable / disable caching |
|
| 43 | + * |
|
| 44 | + * (can be very usefull for the debug of cached scripts) |
|
| 45 | + * |
|
| 46 | + * @var boolean $_caching |
|
| 47 | + */ |
|
| 48 | + public $_caching = true; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Cache lifetime (in seconds) |
|
| 52 | + * |
|
| 53 | + * If null, the cache is valid forever. |
|
| 54 | + * |
|
| 55 | + * @var int $_lifeTime |
|
| 56 | + */ |
|
| 57 | + public $_lifeTime = 3600; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Enable / disable fileLocking |
|
| 61 | + * |
|
| 62 | + * (can avoid cache corruption under bad circumstances) |
|
| 63 | + * |
|
| 64 | + * @var boolean $_fileLocking |
|
| 65 | + */ |
|
| 66 | + public $_fileLocking = true; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Timestamp of the last valid cache |
|
| 70 | + * |
|
| 71 | + * @var int $_refreshTime |
|
| 72 | + */ |
|
| 73 | + public $_refreshTime; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * File name (with path) |
|
| 77 | + * |
|
| 78 | + * @var string $_file |
|
| 79 | + */ |
|
| 80 | + public $_file; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * File name (without path) |
|
| 84 | + * |
|
| 85 | + * @var string $_fileName |
|
| 86 | + */ |
|
| 87 | + public $_fileName; |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Enable / disable write control (the cache is read just after writing to detect corrupt entries) |
|
| 91 | + * |
|
| 92 | + * Enable write control will lightly slow the cache writing but not the cache reading |
|
| 93 | + * Write control can detect some corrupt cache files but maybe it's not a perfect control |
|
| 94 | + * |
|
| 95 | + * @var boolean $_writeControl |
|
| 96 | + */ |
|
| 97 | + public $_writeControl = true; |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Enable / disable read control |
|
| 101 | + * |
|
| 102 | + * If enabled, a control key is embeded in cache file and this key is compared with the one |
|
| 103 | + * calculated after the reading. |
|
| 104 | + * |
|
| 105 | + * @var boolean $_writeControl |
|
| 106 | + */ |
|
| 107 | + public $_readControl = true; |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Type of read control (only if read control is enabled) |
|
| 111 | + * |
|
| 112 | + * Available values are : |
|
| 113 | + * 'md5' for a md5 hash control (best but slowest) |
|
| 114 | + * 'crc32' for a crc32 hash control (lightly less safe but faster, better choice) |
|
| 115 | + * 'strlen' for a length only test (fastest) |
|
| 116 | + * |
|
| 117 | + * @var boolean $_readControlType |
|
| 118 | + */ |
|
| 119 | + public $_readControlType = 'crc32'; |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Pear error mode (when raiseError is called) |
|
| 123 | + * |
|
| 124 | + * (see PEAR doc) |
|
| 125 | + * |
|
| 126 | + * @see setToDebug() |
|
| 127 | + * @var int $_pearErrorMode |
|
| 128 | + */ |
|
| 129 | + public $_pearErrorMode = REFERENCES_CACHE_LITE_ERROR_RETURN; |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Current cache id |
|
| 133 | + * |
|
| 134 | + * @var string $_id |
|
| 135 | + */ |
|
| 136 | + public $_id; |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Current cache group |
|
| 140 | + * |
|
| 141 | + * @var string $_group |
|
| 142 | + */ |
|
| 143 | + public $_group; |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Enable / Disable "Memory Caching" |
|
| 147 | + * |
|
| 148 | + * NB : There is no lifetime for memory caching ! |
|
| 149 | + * |
|
| 150 | + * @var boolean $_memoryCaching |
|
| 151 | + */ |
|
| 152 | + public $_memoryCaching = false; |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Enable / Disable "Only Memory Caching" |
|
| 156 | + * (be carefull, memory caching is "beta quality") |
|
| 157 | + * |
|
| 158 | + * @var boolean $_onlyMemoryCaching |
|
| 159 | + */ |
|
| 160 | + public $_onlyMemoryCaching = false; |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Memory caching array |
|
| 164 | + * |
|
| 165 | + * @var array $_memoryCachingArray |
|
| 166 | + */ |
|
| 167 | + public $_memoryCachingArray = array(); |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * Memory caching counter |
|
| 171 | + * |
|
| 172 | + * @var int $memoryCachingCounter |
|
| 173 | + */ |
|
| 174 | + public $_memoryCachingCounter = 0; |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Memory caching limit |
|
| 178 | + * |
|
| 179 | + * @var int $memoryCachingLimit |
|
| 180 | + */ |
|
| 181 | + public $_memoryCachingLimit = 1000; |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * File Name protection |
|
| 185 | + * |
|
| 186 | + * if set to true, you can use any cache id or group name |
|
| 187 | + * if set to false, it can be faster but cache ids and group names |
|
| 188 | + * will be used directly in cache file names so be carefull with |
|
| 189 | + * special characters... |
|
| 190 | + * |
|
| 191 | + * @var boolean $fileNameProtection |
|
| 192 | + */ |
|
| 193 | + public $_fileNameProtection = true; |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Enable / disable automatic serialization |
|
| 197 | + * |
|
| 198 | + * it can be used to save directly datas which aren't strings |
|
| 199 | + * (but it's slower) |
|
| 200 | + * |
|
| 201 | + * @var boolean $_serialize |
|
| 202 | + */ |
|
| 203 | + public $_automaticSerialization = false; |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * Disable / Tune the automatic cleaning process |
|
| 207 | + * |
|
| 208 | + * The automatic cleaning process destroy too old (for the given life time) |
|
| 209 | + * cache files when a new cache file is written. |
|
| 210 | + * 0 => no automatic cache cleaning |
|
| 211 | + * 1 => systematic cache cleaning |
|
| 212 | + * x (integer) > 1 => automatic cleaning randomly 1 times on x cache write |
|
| 213 | + * |
|
| 214 | + * @var int $_automaticCleaning |
|
| 215 | + */ |
|
| 216 | + public $_automaticCleaningFactor = 0; |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * Nested directory level |
|
| 220 | + * |
|
| 221 | + * Set the hashed directory structure level. 0 means "no hashed directory |
|
| 222 | + * structure", 1 means "one level of directory", 2 means "two levels"... |
|
| 223 | + * This option can speed up Cache_Lite only when you have many thousands of |
|
| 224 | + * cache file. Only specific benchs can help you to choose the perfect value |
|
| 225 | + * for you. Maybe, 1 or 2 is a good start. |
|
| 226 | + * |
|
| 227 | + * @var int $_hashedDirectoryLevel |
|
| 228 | + */ |
|
| 229 | + public $_hashedDirectoryLevel = 0; |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Umask for hashed directory structure |
|
| 233 | + * |
|
| 234 | + * @var int $_hashedDirectoryUmask |
|
| 235 | + */ |
|
| 236 | + public $_hashedDirectoryUmask = 0700; |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * API break for error handling in REFERENCES_CACHE_LITE_ERROR_RETURN mode |
|
| 240 | + * |
|
| 241 | + * In REFERENCES_CACHE_LITE_ERROR_RETURN mode, error handling was not good because |
|
| 242 | + * for example save() method always returned a boolean (a PEAR_Error object |
|
| 243 | + * would be better in REFERENCES_CACHE_LITE_ERROR_RETURN mode). To correct this without |
|
| 244 | + * breaking the API, this option (false by default) can change this handling. |
|
| 245 | + * |
|
| 246 | + * @var boolean |
|
| 247 | + */ |
|
| 248 | + public $_errorHandlingAPIBreak = false; |
|
| 249 | + |
|
| 250 | + // --- Public methods --- |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * Constructor |
|
| 254 | + * |
|
| 255 | + * $options is an assoc. Available options are : |
|
| 256 | + * $options = array( |
|
| 257 | + * 'cacheDir' => directory where to put the cache files (string) , |
|
| 258 | + * 'caching' => enable / disable caching (boolean) , |
|
| 259 | + * 'lifeTime' => cache lifetime in seconds (int) , |
|
| 260 | + * 'fileLocking' => enable / disable fileLocking (boolean) , |
|
| 261 | + * 'writeControl' => enable / disable write control (boolean) , |
|
| 262 | + * 'readControl' => enable / disable read control (boolean) , |
|
| 263 | + * 'readControlType' => type of read control 'crc32', 'md5', 'strlen' (string) , |
|
| 264 | + * 'pearErrorMode' => pear error mode (when raiseError is called) (cf PEAR doc) (int) , |
|
| 265 | + * 'memoryCaching' => enable / disable memory caching (boolean) , |
|
| 266 | + * 'onlyMemoryCaching' => enable / disable only memory caching (boolean) , |
|
| 267 | + * 'memoryCachingLimit' => max nbr of records to store into memory caching (int) , |
|
| 268 | + * 'fileNameProtection' => enable / disable automatic file name protection (boolean) , |
|
| 269 | + * 'automaticSerialization' => enable / disable automatic serialization (boolean) , |
|
| 270 | + * 'automaticCleaningFactor' => distable / tune automatic cleaning process (int) , |
|
| 271 | + * 'hashedDirectoryLevel' => level of the hashed directory system (int) , |
|
| 272 | + * 'hashedDirectoryUmask' => umask for hashed directory structure (int) , |
|
| 273 | + * 'errorHandlingAPIBreak' => API break for better error handling ? (boolean) |
|
| 274 | + * ); |
|
| 275 | + * |
|
| 276 | + * @param array $options options |
|
| 277 | + * @access public |
|
| 278 | + */ |
|
| 279 | + public function __construct($options = array(null)) |
|
| 280 | + { |
|
| 281 | + foreach ($options as $key => $value) { |
|
| 282 | + $this->setOption($key, $value); |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * Generic way to set a Cache_Lite option |
|
| 288 | + * |
|
| 289 | + * see Cache_Lite constructor for available options |
|
| 290 | + * |
|
| 291 | + * @var string $name name of the option |
|
| 292 | + * @var mixed $value value of the option |
|
| 293 | + * @access public |
|
| 294 | + */ |
|
| 295 | + public function setOption($name, $value) |
|
| 296 | + { |
|
| 297 | + $availableOptions = array( |
|
| 298 | + 'errorHandlingAPIBreak', |
|
| 299 | + 'hashedDirectoryUmask', |
|
| 300 | + 'hashedDirectoryLevel', |
|
| 301 | + 'automaticCleaningFactor', |
|
| 302 | + 'automaticSerialization', |
|
| 303 | + 'fileNameProtection', |
|
| 304 | + 'memoryCaching', |
|
| 305 | + 'onlyMemoryCaching', |
|
| 306 | + 'memoryCachingLimit', |
|
| 307 | + 'cacheDir', |
|
| 308 | + 'caching', |
|
| 309 | + 'lifeTime', |
|
| 310 | + 'fileLocking', |
|
| 311 | + 'writeControl', |
|
| 312 | + 'readControl', |
|
| 313 | + 'readControlType', |
|
| 314 | + 'pearErrorMode' |
|
| 315 | + ); |
|
| 316 | + if (in_array($name, $availableOptions)) { |
|
| 317 | + $property = '_' . $name; |
|
| 318 | + $this->$property = $value; |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * Test if a cache is available and (if yes) return it |
|
| 324 | + * |
|
| 325 | + * @param string $id cache id |
|
| 326 | + * @param string $group name of the cache group |
|
| 327 | + * @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested |
|
| 328 | + * @return string data of the cache (else : false) |
|
| 329 | + * @access public |
|
| 330 | + */ |
|
| 331 | + public function get($id, $group = 'default', $doNotTestCacheValidity = false) |
|
| 332 | + { |
|
| 333 | + $this->_id = $id; |
|
| 334 | + $this->_group = $group; |
|
| 335 | + $data = false; |
|
| 336 | + if ($this->_caching) { |
|
| 337 | + $this->_setRefreshTime(); |
|
| 338 | + $this->_setFileName($id, $group); |
|
| 339 | + clearstatcache(); |
|
| 340 | + if ($this->_memoryCaching) { |
|
| 341 | + if (isset($this->_memoryCachingArray[$this->_file])) { |
|
| 342 | + if ($this->_automaticSerialization) { |
|
| 343 | + return unserialize($this->_memoryCachingArray[$this->_file]); |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + return $this->_memoryCachingArray[$this->_file]; |
|
| 347 | + } |
|
| 348 | + if ($this->_onlyMemoryCaching) { |
|
| 349 | + return false; |
|
| 350 | + } |
|
| 351 | + } |
|
| 352 | + if ($doNotTestCacheValidity || is_null($this->_refreshTime)) { |
|
| 353 | + if (file_exists($this->_file)) { |
|
| 354 | + $data = $this->_read(); |
|
| 355 | + } |
|
| 356 | + } else { |
|
| 357 | + if (file_exists($this->_file) && (@filemtime($this->_file) > $this->_refreshTime)) { |
|
| 358 | + $data = $this->_read(); |
|
| 359 | + } |
|
| 360 | + } |
|
| 361 | + if ($data && $this->_memoryCaching) { |
|
| 362 | + $this->_memoryCacheAdd($data); |
|
| 363 | + } |
|
| 364 | + if ($this->_automaticSerialization && is_string($data)) { |
|
| 365 | + $data = unserialize($data); |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + return $data; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + return false; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * Save some data in a cache file |
|
| 376 | + * |
|
| 377 | + * @param string $data data to put in cache (can be another type than strings if automaticSerialization is on) |
|
| 378 | + * @param string $id cache id |
|
| 379 | + * @param string $group name of the cache group |
|
| 380 | + * @return boolean true if no problem (else : false or a PEAR_Error object) |
|
| 381 | + * @access public |
|
| 382 | + */ |
|
| 383 | + public function save($data, $id = null, $group = 'default') |
|
| 384 | + { |
|
| 385 | + if ($this->_caching) { |
|
| 386 | + if ($this->_automaticSerialization) { |
|
| 387 | + $data = serialize($data); |
|
| 388 | + } |
|
| 389 | + if (isset($id)) { |
|
| 390 | + $this->_setFileName($id, $group); |
|
| 391 | + } |
|
| 392 | + if ($this->_memoryCaching) { |
|
| 393 | + $this->_memoryCacheAdd($data); |
|
| 394 | + if ($this->_onlyMemoryCaching) { |
|
| 395 | + return true; |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | + if ($this->_automaticCleaningFactor > 0 && ($this->_automaticCleaningFactor == 1 || mt_rand(1, $this->_automaticCleaningFactor) == 1)) { |
|
| 399 | + $this->clean(false, 'old'); |
|
| 400 | + } |
|
| 401 | + if ($this->_writeControl) { |
|
| 402 | + $res = $this->_writeAndControl($data); |
|
| 403 | + if (is_bool($res)) { |
|
| 404 | + if ($res) { |
|
| 405 | + return true; |
|
| 406 | + } |
|
| 407 | + // if $res if false, we need to invalidate the cache |
|
| 408 | + @touch($this->_file, time() - 2 * abs($this->_lifeTime)); |
|
| 409 | + |
|
| 410 | + return false; |
|
| 411 | + } |
|
| 412 | + } else { |
|
| 413 | + $res = $this->_write($data); |
|
| 414 | + } |
|
| 415 | + if (is_object($res)) { |
|
| 416 | + // $res is a PEAR_Error object |
|
| 417 | + if (!$this->_errorHandlingAPIBreak) { |
|
| 418 | + return false; // we return false (old API) |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + return $res; |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + return false; |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + /** |
|
| 429 | + * Remove a cache file |
|
| 430 | + * |
|
| 431 | + * @param string $id cache id |
|
| 432 | + * @param string $group name of the cache group |
|
| 433 | + * @param boolean $checkbeforeunlink check if file exists before removing it |
|
| 434 | + * @return boolean true if no problem |
|
| 435 | + * @access public |
|
| 436 | + */ |
|
| 437 | + public function remove($id, $group = 'default', $checkbeforeunlink = false) |
|
| 438 | + { |
|
| 439 | + $this->_setFileName($id, $group); |
|
| 440 | + if ($this->_memoryCaching) { |
|
| 441 | + if (isset($this->_memoryCachingArray[$this->_file])) { |
|
| 442 | + unset($this->_memoryCachingArray[$this->_file]); |
|
| 443 | + --$this->_memoryCachingCounter; |
|
| 444 | + } |
|
| 445 | + if ($this->_onlyMemoryCaching) { |
|
| 446 | + return true; |
|
| 447 | + } |
|
| 448 | + } |
|
| 449 | + if ($checkbeforeunlink) { |
|
| 450 | + if (!file_exists($this->_file)) { |
|
| 451 | + return true; |
|
| 452 | + } |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + return $this->_unlink($this->_file); |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * Clean the cache |
|
| 460 | + * |
|
| 461 | + * if no group is specified all cache files will be destroyed |
|
| 462 | + * else only cache files of the specified group will be destroyed |
|
| 463 | + * |
|
| 464 | + * @param bool|string $group name of the cache group |
|
| 465 | + * @param string $mode flush cache mode : 'old', 'ingroup', 'notingroup', |
|
| 466 | + * 'callback_myFunction' |
|
| 467 | + * @return bool true if no problem |
|
| 468 | + * @access public |
|
| 469 | + */ |
|
| 470 | + public function clean($group = false, $mode = 'ingroup') |
|
| 471 | + { |
|
| 472 | + return $this->_cleanDir($this->_cacheDir, $group, $mode); |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + /** |
|
| 476 | + * Set to debug mode |
|
| 477 | + * |
|
| 478 | + * When an error is found, the script will stop and the message will be displayed |
|
| 479 | + * (in debug mode only). |
|
| 480 | + * |
|
| 481 | + * @access public |
|
| 482 | + */ |
|
| 483 | + public function setToDebug() |
|
| 484 | + { |
|
| 485 | + $this->setOption('pearErrorMode', REFERENCES_CACHE_LITE_ERROR_DIE); |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + /** |
|
| 489 | + * Set a new life time |
|
| 490 | + * |
|
| 491 | + * @param int $newLifeTime new life time (in seconds) |
|
| 492 | + * @access public |
|
| 493 | + */ |
|
| 494 | + public function setLifeTime($newLifeTime) |
|
| 495 | + { |
|
| 496 | + $this->_lifeTime = $newLifeTime; |
|
| 497 | + $this->_setRefreshTime(); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + /** |
|
| 501 | + * Save the state of the caching memory array into a cache file cache |
|
| 502 | + * |
|
| 503 | + * @param string $id cache id |
|
| 504 | + * @param string $group name of the cache group |
|
| 505 | + * @access public |
|
| 506 | + */ |
|
| 507 | + public function saveMemoryCachingState($id, $group = 'default') |
|
| 508 | + { |
|
| 509 | + if ($this->_caching) { |
|
| 510 | + $array = array( |
|
| 511 | + 'counter' => $this->_memoryCachingCounter, |
|
| 512 | + 'array' => $this->_memoryCachingArray |
|
| 513 | + ); |
|
| 514 | + $data = serialize($array); |
|
| 515 | + $this->save($data, $id, $group); |
|
| 516 | + } |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + /** |
|
| 520 | + * Load the state of the caching memory array from a given cache file cache |
|
| 521 | + * |
|
| 522 | + * @param string $id cache id |
|
| 523 | + * @param string $group name of the cache group |
|
| 524 | + * @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested |
|
| 525 | + * @access public |
|
| 526 | + */ |
|
| 527 | + public function getMemoryCachingState($id, $group = 'default', $doNotTestCacheValidity = false) |
|
| 528 | + { |
|
| 529 | + if ($this->_caching) { |
|
| 530 | + if ($data = $this->get($id, $group, $doNotTestCacheValidity)) { |
|
| 531 | + $array = unserialize($data); |
|
| 532 | + $this->_memoryCachingCounter = $array['counter']; |
|
| 533 | + $this->_memoryCachingArray = $array['array']; |
|
| 534 | + } |
|
| 535 | + } |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + /** |
|
| 539 | + * Return the cache last modification time |
|
| 540 | + * |
|
| 541 | + * BE CAREFUL : THIS METHOD IS FOR HACKING ONLY ! |
|
| 542 | + * |
|
| 543 | + * @return int last modification time |
|
| 544 | + */ |
|
| 545 | + public function lastModified() |
|
| 546 | + { |
|
| 547 | + return @filemtime($this->_file); |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + /** |
|
| 551 | + * Trigger a PEAR error |
|
| 552 | + * |
|
| 553 | + * To improve performances, the PEAR.php file is included dynamically. |
|
| 554 | + * The file is so included only when an error is triggered. So, in most |
|
| 555 | + * cases, the file isn't included and perfs are much better. |
|
| 556 | + * |
|
| 557 | + * @param string $msg error message |
|
| 558 | + * @param int $code error code |
|
| 559 | + * @access public |
|
| 560 | + * @return object |
|
| 561 | + */ |
|
| 562 | + public function raiseError($msg, $code) |
|
| 563 | + { |
|
| 564 | + include_once('PEAR.php'); |
|
| 565 | + |
|
| 566 | + return references_PEAR::raiseError($msg, $code, $this->_pearErrorMode); |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + /** |
|
| 570 | + * Extend the life of a valid cache file |
|
| 571 | + * |
|
| 572 | + * see http://pear.php.net/bugs/bug.php?id=6681 |
|
| 573 | + * |
|
| 574 | + * @access public |
|
| 575 | + */ |
|
| 576 | + public function extendLife() |
|
| 577 | + { |
|
| 578 | + @touch($this->_file); |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + // --- Private methods --- |
|
| 582 | + |
|
| 583 | + /** |
|
| 584 | + * Compute & set the refresh time |
|
| 585 | + * |
|
| 586 | + * @access private |
|
| 587 | + */ |
|
| 588 | + public function _setRefreshTime() |
|
| 589 | + { |
|
| 590 | + if (is_null($this->_lifeTime)) { |
|
| 591 | + $this->_refreshTime = null; |
|
| 592 | + } else { |
|
| 593 | + $this->_refreshTime = time() - $this->_lifeTime; |
|
| 594 | + } |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + /** |
|
| 598 | + * Remove a file |
|
| 599 | + * |
|
| 600 | + * @param string $file complete file path and name |
|
| 601 | + * @return boolean true if no problem |
|
| 602 | + * @access private |
|
| 603 | + */ |
|
| 604 | + public function _unlink($file) |
|
| 605 | + { |
|
| 606 | + if (!@unlink($file)) { |
|
| 607 | + return $this->raiseError('Cache_Lite : Unable to remove cache !', -3); |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + return true; |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + /** |
|
| 614 | + * Recursive function for cleaning cache file in the given directory |
|
| 615 | + * |
|
| 616 | + * @param string $dir directory complete path (with a trailing slash) |
|
| 617 | + * @param bool|string $group name of the cache group |
|
| 618 | + * @param string $mode flush cache mode : 'old', 'ingroup', 'notingroup', |
|
| 619 | + * 'callback_myFunction' |
|
| 620 | + * @return bool true if no problem |
|
| 621 | + * @access private |
|
| 622 | + */ |
|
| 623 | + public function _cleanDir($dir, $group = false, $mode = 'ingroup') |
|
| 624 | + { |
|
| 625 | + if ($this->_fileNameProtection) { |
|
| 626 | + $motif = $group ? 'cache_' . md5($group) . '_' : 'cache_'; |
|
| 627 | + } else { |
|
| 628 | + $motif = $group ? 'cache_' . $group . '_' : 'cache_'; |
|
| 629 | + } |
|
| 630 | + if ($this->_memoryCaching) { |
|
| 631 | + foreach ($this->_memoryCachingArray as $key => $v) { |
|
| 632 | + if (strpos($key, $motif) !== false) { |
|
| 633 | + unset($this->_memoryCachingArray[$key]); |
|
| 634 | + --$this->_memoryCachingCounter; |
|
| 635 | + } |
|
| 636 | + } |
|
| 637 | + if ($this->_onlyMemoryCaching) { |
|
| 638 | + return true; |
|
| 639 | + } |
|
| 640 | + } |
|
| 641 | + if (!($dh = opendir($dir))) { |
|
| 642 | + return $this->raiseError('Cache_Lite : Unable to open cache directory !', -4); |
|
| 643 | + } |
|
| 644 | + $result = true; |
|
| 645 | + while ($file = readdir($dh)) { |
|
| 646 | + if (($file !== '.') && ($file !== '..')) { |
|
| 647 | + if (substr($file, 0, 6) === 'cache_') { |
|
| 648 | + $file2 = $dir . $file; |
|
| 649 | + if (is_file($file2)) { |
|
| 650 | + switch (substr($mode, 0, 9)) { |
|
| 651 | + case 'old': |
|
| 652 | + // files older than lifeTime get deleted from cache |
|
| 653 | + if (!is_null($this->_lifeTime)) { |
|
| 654 | + if ((time() - @filemtime($file2)) > $this->_lifeTime) { |
|
| 655 | + $result = ($result and $this->_unlink($file2)); |
|
| 656 | + } |
|
| 657 | + } |
|
| 658 | + break; |
|
| 659 | + case 'notingrou': |
|
| 660 | + if (strpos($file2, $motif) === false) { |
|
| 661 | + $result = ($result and $this->_unlink($file2)); |
|
| 662 | + } |
|
| 663 | + break; |
|
| 664 | + case 'callback_': |
|
| 665 | + $func = substr($mode, 9, strlen($mode) - 9); |
|
| 666 | + if ($func($file2, $group)) { |
|
| 667 | + $result = ($result and $this->_unlink($file2)); |
|
| 668 | + } |
|
| 669 | + break; |
|
| 670 | + case 'ingroup': |
|
| 671 | + default: |
|
| 672 | + if (strpos($file2, $motif) !== false) { |
|
| 673 | + $result = ($result and $this->_unlink($file2)); |
|
| 674 | + } |
|
| 675 | + break; |
|
| 676 | + } |
|
| 677 | + } |
|
| 678 | + if (is_dir($file2) and ($this->_hashedDirectoryLevel > 0)) { |
|
| 679 | + $result = ($result and $this->_cleanDir($file2 . '/', $group, $mode)); |
|
| 680 | + } |
|
| 681 | + } |
|
| 682 | + } |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + return $result; |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + /** |
|
| 689 | + * Add some date in the memory caching array |
|
| 690 | + * |
|
| 691 | + * @param string $data data to cache |
|
| 692 | + * @access private |
|
| 693 | + */ |
|
| 694 | + public function _memoryCacheAdd($data) |
|
| 695 | + { |
|
| 696 | + $this->_memoryCachingArray[$this->_file] = $data; |
|
| 697 | + if ($this->_memoryCachingCounter >= $this->_memoryCachingLimit) { |
|
| 698 | + list($key,) = each($this->_memoryCachingArray); |
|
| 699 | + unset($this->_memoryCachingArray[$key]); |
|
| 700 | + } else { |
|
| 701 | + ++$this->_memoryCachingCounter; |
|
| 702 | + } |
|
| 703 | + } |
|
| 704 | + |
|
| 705 | + /** |
|
| 706 | + * Make a file name (with path) |
|
| 707 | + * |
|
| 708 | + * @param string $id cache id |
|
| 709 | + * @param string $group name of the group |
|
| 710 | + * @access private |
|
| 711 | + */ |
|
| 712 | + public function _setFileName($id, $group) |
|
| 713 | + { |
|
| 714 | + if ($this->_fileNameProtection) { |
|
| 715 | + $suffix = 'cache_' . md5($group) . '_' . md5($id); |
|
| 716 | + } else { |
|
| 717 | + $suffix = 'cache_' . $group . '_' . $id; |
|
| 718 | + } |
|
| 719 | + $root = $this->_cacheDir; |
|
| 720 | + if ($this->_hashedDirectoryLevel > 0) { |
|
| 721 | + $hash = md5($suffix); |
|
| 722 | + for ($i = 0; $i < $this->_hashedDirectoryLevel; ++$i) { |
|
| 723 | + $root = $root . 'cache_' . substr($hash, 0, $i + 1) . '/'; |
|
| 724 | + } |
|
| 725 | + } |
|
| 726 | + $this->_fileName = $suffix; |
|
| 727 | + $this->_file = $root . $suffix; |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + /** |
|
| 731 | + * Read the cache file and return the content |
|
| 732 | + * |
|
| 733 | + * @return string content of the cache file (else : false or a PEAR_Error object) |
|
| 734 | + * @access private |
|
| 735 | + */ |
|
| 736 | + public function _read() |
|
| 737 | + { |
|
| 738 | + $fp = @fopen($this->_file, 'rb'); |
|
| 739 | + if ($this->_fileLocking) { |
|
| 740 | + @flock($fp, LOCK_SH); |
|
| 741 | + } |
|
| 742 | + if ($fp) { |
|
| 743 | + clearstatcache(); |
|
| 744 | + $length = @filesize($this->_file); |
|
| 745 | + // $mqr = get_magic_quotes_runtime(); |
|
| 746 | + // @set_magic_quotes_runtime(0); |
|
| 747 | + if ($this->_readControl) { |
|
| 748 | + $hashControl = @fread($fp, 32); |
|
| 749 | + $length = $length - 32; |
|
| 750 | + } |
|
| 751 | + if ($length) { |
|
| 752 | + $data = @fread($fp, $length); |
|
| 753 | + } else { |
|
| 754 | + $data = ''; |
|
| 755 | + } |
|
| 756 | + // @set_magic_quotes_runtime($mqr); |
|
| 757 | + if ($this->_fileLocking) { |
|
| 758 | + @flock($fp, LOCK_UN); |
|
| 759 | + } |
|
| 760 | + @fclose($fp); |
|
| 761 | + if ($this->_readControl) { |
|
| 762 | + $hashData = $this->_hash($data, $this->_readControlType); |
|
| 763 | + if ($hashData != $hashControl) { |
|
| 764 | + if (!is_null($this->_lifeTime)) { |
|
| 765 | + @touch($this->_file, time() - 2 * abs($this->_lifeTime)); |
|
| 766 | + } else { |
|
| 767 | + @unlink($this->_file); |
|
| 768 | + } |
|
| 769 | + |
|
| 770 | + return false; |
|
| 771 | + } |
|
| 772 | + } |
|
| 773 | + |
|
| 774 | + return $data; |
|
| 775 | + } |
|
| 776 | + |
|
| 777 | + return $this->raiseError('Cache_Lite : Unable to read cache !', -2); |
|
| 778 | + } |
|
| 779 | + |
|
| 780 | + /** |
|
| 781 | + * Write the given data in the cache file |
|
| 782 | + * |
|
| 783 | + * @param string $data data to put in cache |
|
| 784 | + * @return boolean true if ok (a PEAR_Error object else) |
|
| 785 | + * @access private |
|
| 786 | + */ |
|
| 787 | + public function _write($data) |
|
| 788 | + { |
|
| 789 | + if ($this->_hashedDirectoryLevel > 0) { |
|
| 790 | + $hash = md5($this->_fileName); |
|
| 791 | + $root = $this->_cacheDir; |
|
| 792 | + for ($i = 0; $i < $this->_hashedDirectoryLevel; ++$i) { |
|
| 793 | + $root = $root . 'cache_' . substr($hash, 0, $i + 1) . '/'; |
|
| 794 | + if (!(@is_dir($root))) { |
|
| 795 | + @mkdir($root, $this->_hashedDirectoryUmask); |
|
| 796 | + } |
|
| 797 | + } |
|
| 798 | + } |
|
| 799 | + $fp = @fopen($this->_file, 'wb'); |
|
| 800 | + if ($fp) { |
|
| 801 | + if ($this->_fileLocking) { |
|
| 802 | + @flock($fp, LOCK_EX); |
|
| 803 | + } |
|
| 804 | + if ($this->_readControl) { |
|
| 805 | + @fwrite($fp, $this->_hash($data, $this->_readControlType), 32); |
|
| 806 | + } |
|
| 807 | + // $mqr = get_magic_quotes_runtime(); |
|
| 808 | + // @set_magic_quotes_runtime(0); |
|
| 809 | + @fwrite($fp, $data); |
|
| 810 | + // @set_magic_quotes_runtime($mqr); |
|
| 811 | + if ($this->_fileLocking) { |
|
| 812 | + @flock($fp, LOCK_UN); |
|
| 813 | + } |
|
| 814 | + @fclose($fp); |
|
| 815 | + |
|
| 816 | + return true; |
|
| 817 | + } |
|
| 818 | + |
|
| 819 | + return $this->raiseError('Cache_Lite : Unable to write cache file : ' . $this->_file, -1); |
|
| 820 | + } |
|
| 821 | + |
|
| 822 | + /** |
|
| 823 | + * Write the given data in the cache file and control it just after to avoir corrupted cache entries |
|
| 824 | + * |
|
| 825 | + * @param string $data data to put in cache |
|
| 826 | + * @return boolean true if the test is ok (else : false or a PEAR_Error object) |
|
| 827 | + * @access private |
|
| 828 | + */ |
|
| 829 | + public function _writeAndControl($data) |
|
| 830 | + { |
|
| 831 | + $result = $this->_write($data); |
|
| 832 | + if (is_object($result)) { |
|
| 833 | + return $result; # We return the PEAR_Error object |
|
| 834 | + } |
|
| 835 | + $dataRead = $this->_read(); |
|
| 836 | + if (is_object($dataRead)) { |
|
| 837 | + return $dataRead; # We return the PEAR_Error object |
|
| 838 | + } |
|
| 839 | + if (is_bool($dataRead) && (!$dataRead)) { |
|
| 840 | + return false; |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + return ($dataRead == $data); |
|
| 844 | + } |
|
| 845 | + |
|
| 846 | + /** |
|
| 847 | + * Make a control key with the string containing datas |
|
| 848 | + * |
|
| 849 | + * @param string $data data |
|
| 850 | + * @param string $controlType type of control 'md5', 'crc32' or 'strlen' |
|
| 851 | + * @return string control key |
|
| 852 | + * @access private |
|
| 853 | + */ |
|
| 854 | + public function _hash($data, $controlType) |
|
| 855 | + { |
|
| 856 | + switch ($controlType) { |
|
| 857 | + case 'md5': |
|
| 858 | + return md5($data); |
|
| 859 | + case 'crc32': |
|
| 860 | + return sprintf('% 32d', crc32($data)); |
|
| 861 | + case 'strlen': |
|
| 862 | + return sprintf('% 32d', strlen($data)); |
|
| 863 | + default: |
|
| 864 | + return $this->raiseError('Unknown controlType ! (available values are only \'md5\', \'crc32\', \'strlen\')', -5); |
|
| 865 | + } |
|
| 866 | + } |
|
| 867 | 867 | } |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | 'pearErrorMode' |
| 315 | 315 | ); |
| 316 | 316 | if (in_array($name, $availableOptions)) { |
| 317 | - $property = '_' . $name; |
|
| 317 | + $property = '_'.$name; |
|
| 318 | 318 | $this->$property = $value; |
| 319 | 319 | } |
| 320 | 320 | } |
@@ -511,7 +511,7 @@ discard block |
||
| 511 | 511 | 'counter' => $this->_memoryCachingCounter, |
| 512 | 512 | 'array' => $this->_memoryCachingArray |
| 513 | 513 | ); |
| 514 | - $data = serialize($array); |
|
| 514 | + $data = serialize($array); |
|
| 515 | 515 | $this->save($data, $id, $group); |
| 516 | 516 | } |
| 517 | 517 | } |
@@ -623,9 +623,9 @@ discard block |
||
| 623 | 623 | public function _cleanDir($dir, $group = false, $mode = 'ingroup') |
| 624 | 624 | { |
| 625 | 625 | if ($this->_fileNameProtection) { |
| 626 | - $motif = $group ? 'cache_' . md5($group) . '_' : 'cache_'; |
|
| 626 | + $motif = $group ? 'cache_'.md5($group).'_' : 'cache_'; |
|
| 627 | 627 | } else { |
| 628 | - $motif = $group ? 'cache_' . $group . '_' : 'cache_'; |
|
| 628 | + $motif = $group ? 'cache_'.$group.'_' : 'cache_'; |
|
| 629 | 629 | } |
| 630 | 630 | if ($this->_memoryCaching) { |
| 631 | 631 | foreach ($this->_memoryCachingArray as $key => $v) { |
@@ -645,7 +645,7 @@ discard block |
||
| 645 | 645 | while ($file = readdir($dh)) { |
| 646 | 646 | if (($file !== '.') && ($file !== '..')) { |
| 647 | 647 | if (substr($file, 0, 6) === 'cache_') { |
| 648 | - $file2 = $dir . $file; |
|
| 648 | + $file2 = $dir.$file; |
|
| 649 | 649 | if (is_file($file2)) { |
| 650 | 650 | switch (substr($mode, 0, 9)) { |
| 651 | 651 | case 'old': |
@@ -676,7 +676,7 @@ discard block |
||
| 676 | 676 | } |
| 677 | 677 | } |
| 678 | 678 | if (is_dir($file2) and ($this->_hashedDirectoryLevel > 0)) { |
| 679 | - $result = ($result and $this->_cleanDir($file2 . '/', $group, $mode)); |
|
| 679 | + $result = ($result and $this->_cleanDir($file2.'/', $group, $mode)); |
|
| 680 | 680 | } |
| 681 | 681 | } |
| 682 | 682 | } |
@@ -712,19 +712,19 @@ discard block |
||
| 712 | 712 | public function _setFileName($id, $group) |
| 713 | 713 | { |
| 714 | 714 | if ($this->_fileNameProtection) { |
| 715 | - $suffix = 'cache_' . md5($group) . '_' . md5($id); |
|
| 715 | + $suffix = 'cache_'.md5($group).'_'.md5($id); |
|
| 716 | 716 | } else { |
| 717 | - $suffix = 'cache_' . $group . '_' . $id; |
|
| 717 | + $suffix = 'cache_'.$group.'_'.$id; |
|
| 718 | 718 | } |
| 719 | 719 | $root = $this->_cacheDir; |
| 720 | 720 | if ($this->_hashedDirectoryLevel > 0) { |
| 721 | 721 | $hash = md5($suffix); |
| 722 | 722 | for ($i = 0; $i < $this->_hashedDirectoryLevel; ++$i) { |
| 723 | - $root = $root . 'cache_' . substr($hash, 0, $i + 1) . '/'; |
|
| 723 | + $root = $root.'cache_'.substr($hash, 0, $i + 1).'/'; |
|
| 724 | 724 | } |
| 725 | 725 | } |
| 726 | 726 | $this->_fileName = $suffix; |
| 727 | - $this->_file = $root . $suffix; |
|
| 727 | + $this->_file = $root.$suffix; |
|
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | /** |
@@ -790,7 +790,7 @@ discard block |
||
| 790 | 790 | $hash = md5($this->_fileName); |
| 791 | 791 | $root = $this->_cacheDir; |
| 792 | 792 | for ($i = 0; $i < $this->_hashedDirectoryLevel; ++$i) { |
| 793 | - $root = $root . 'cache_' . substr($hash, 0, $i + 1) . '/'; |
|
| 793 | + $root = $root.'cache_'.substr($hash, 0, $i + 1).'/'; |
|
| 794 | 794 | if (!(@is_dir($root))) { |
| 795 | 795 | @mkdir($root, $this->_hashedDirectoryUmask); |
| 796 | 796 | } |
@@ -816,7 +816,7 @@ discard block |
||
| 816 | 816 | return true; |
| 817 | 817 | } |
| 818 | 818 | |
| 819 | - return $this->raiseError('Cache_Lite : Unable to write cache file : ' . $this->_file, -1); |
|
| 819 | + return $this->raiseError('Cache_Lite : Unable to write cache file : '.$this->_file, -1); |
|
| 820 | 820 | } |
| 821 | 821 | |
| 822 | 822 | /** |
@@ -24,34 +24,34 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class references_handler |
| 26 | 26 | { |
| 27 | - public $h_references_articles = null; |
|
| 28 | - public $h_references_categories = null; |
|
| 29 | - private static $instance = false; |
|
| 27 | + public $h_references_articles = null; |
|
| 28 | + public $h_references_categories = null; |
|
| 29 | + private static $instance = false; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Singleton |
|
| 33 | - */ |
|
| 34 | - private function __construct() |
|
| 35 | - { |
|
| 36 | - $handlersNames = array('references_articles', 'references_categories'); |
|
| 37 | - foreach ($handlersNames as $handlerName) { |
|
| 38 | - $internalName = 'h_' . $handlerName; |
|
| 39 | - $this->$internalName = xoops_getModuleHandler($handlerName, REFERENCES_DIRNAME); |
|
| 40 | - } |
|
| 41 | - } |
|
| 31 | + /** |
|
| 32 | + * Singleton |
|
| 33 | + */ |
|
| 34 | + private function __construct() |
|
| 35 | + { |
|
| 36 | + $handlersNames = array('references_articles', 'references_categories'); |
|
| 37 | + foreach ($handlersNames as $handlerName) { |
|
| 38 | + $internalName = 'h_' . $handlerName; |
|
| 39 | + $this->$internalName = xoops_getModuleHandler($handlerName, REFERENCES_DIRNAME); |
|
| 40 | + } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Retourne l'instance unique de la clanss |
|
| 45 | - * |
|
| 46 | - * @return object |
|
| 47 | - */ |
|
| 48 | - public static function getInstance() |
|
| 49 | - { |
|
| 50 | - static $instance; |
|
| 51 | - if (null === $instance) { |
|
| 52 | - $instance = new static(); |
|
| 53 | - } |
|
| 43 | + /** |
|
| 44 | + * Retourne l'instance unique de la clanss |
|
| 45 | + * |
|
| 46 | + * @return object |
|
| 47 | + */ |
|
| 48 | + public static function getInstance() |
|
| 49 | + { |
|
| 50 | + static $instance; |
|
| 51 | + if (null === $instance) { |
|
| 52 | + $instance = new static(); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - return $instance; |
|
| 56 | - } |
|
| 55 | + return $instance; |
|
| 56 | + } |
|
| 57 | 57 | } |
@@ -35,7 +35,7 @@ |
||
| 35 | 35 | { |
| 36 | 36 | $handlersNames = array('references_articles', 'references_categories'); |
| 37 | 37 | foreach ($handlersNames as $handlerName) { |
| 38 | - $internalName = 'h_' . $handlerName; |
|
| 38 | + $internalName = 'h_'.$handlerName; |
|
| 39 | 39 | $this->$internalName = xoops_getModuleHandler($handlerName, REFERENCES_DIRNAME); |
| 40 | 40 | } |
| 41 | 41 | } |