/public/js/tiny_mce/plugins/imagemanager/plugins/History/History.php

https://bitbucket.org/cidious/raise.org · PHP · 213 lines · 138 code · 45 blank · 30 comment · 25 complexity · f082f05f6eccd09fc519c6153d814717 MD5 · raw file

  1. <?php
  2. /**
  3. * HistoryCookiePlugin.php
  4. *
  5. * @package HistoryCookiePlugin
  6. * @author Moxiecode
  7. * @copyright Copyright � 2007, Moxiecode Systems AB, All rights reserved.
  8. */
  9. /**
  10. * This class handles MCImageManager HistoryCookiePlugin stuff.
  11. *
  12. * @package HistoryCookiePlugin
  13. */
  14. class Moxiecode_HistoryPlugin extends Moxiecode_ManagerPlugin {
  15. /**#@+
  16. * @access public
  17. */
  18. var $_maxhistory = 10;
  19. /**
  20. * ..
  21. */
  22. function Moxiecode_HistoryPlugin() {
  23. }
  24. function onInit(&$man) {
  25. $man->registerFileSystem('history', 'Moxiecode_HistoryFile');
  26. return true;
  27. }
  28. function onInsertFile(&$man, &$file) {
  29. $path = $file->getAbsolutePath();
  30. $type = $man->getType();
  31. $maxhistory = isset($config["history.max"]) ? $config["history.max"] : $this->_maxhistory;
  32. $cookievalue = $this->getCookieData($type);
  33. $patharray = array();
  34. $patharray = split(",", $cookievalue);
  35. if (count($patharray) > 0) {
  36. for($i=0;$i<count($patharray);$i++) {
  37. if ($patharray[$i] == $path) {
  38. array_splice($patharray, $i, 1);
  39. break;
  40. }
  41. }
  42. array_unshift($patharray, $path);
  43. if (count($patharray) > $maxhistory)
  44. array_pop($patharray);
  45. } else
  46. $patharray[] = $path;
  47. $cookievalue = implode(",", $patharray);
  48. $this->setCookieData($type, $cookievalue);
  49. return true;
  50. }
  51. function getCookieData($type) {
  52. if (isset($_COOKIE["MCManagerHistoryCookie_". $type]))
  53. return $_COOKIE["MCManagerHistoryCookie_". $type];
  54. else
  55. return "";
  56. }
  57. function setCookieData($type, $val) {
  58. setcookie("MCManagerHistoryCookie_". $type, $val, time()+(3600*24*30)); // 30 days
  59. }
  60. function onClearHistory(&$man) {
  61. setcookie ("MCManagerHistoryCookie_". $man->getType(), "", time() - 3600); // 1 hour ago
  62. return true;
  63. }
  64. }
  65. class Moxiecode_HistoryFile extends Moxiecode_BaseFileImpl {
  66. function Moxiecode_HistoryFile(&$manager, $absolute_path, $child_name = "", $type = MC_IS_FILE) {
  67. $absolute_path = str_replace('favorite://', '', $absolute_path);
  68. Moxiecode_BaseFileImpl::Moxiecode_BaseFileImpl($manager, $absolute_path, $child_name, $type);
  69. }
  70. function canRead() {
  71. return true;
  72. }
  73. function canWrite() {
  74. return false;
  75. }
  76. function exists() {
  77. return true;
  78. }
  79. function isDirectory() {
  80. return true;
  81. }
  82. function isFile() {
  83. return false;
  84. }
  85. function getParent() {
  86. return null;
  87. }
  88. function &getParentFile() {
  89. return null;
  90. }
  91. /**
  92. * Returns an array of File instances.
  93. *
  94. * @return Array array of File instances.
  95. */
  96. function &listFiles() {
  97. $files = $this->listFilesFiltered(new Moxiecode_DummyFileFilter());
  98. return $files;
  99. }
  100. /**
  101. * Returns an array of MCE_File instances based on the specified filter instance.
  102. *
  103. * @param MCE_FileFilter &$filter MCE_FileFilter instance to filter files by.
  104. * @return Array array of MCE_File instances based on the specified filter instance.
  105. */
  106. function &listFilesFiltered(&$filter) {
  107. $files = array();
  108. $man = $this->_manager;
  109. $type = $man->getType();
  110. $cookievalue = $this->_getCookieData($type);
  111. $patharray = array();
  112. if (IndexOf($cookievalue, ",") != -1)
  113. $patharray = split(",", $cookievalue);
  114. else if ($cookievalue != "")
  115. $patharray[] = $cookievalue;
  116. foreach ($patharray as $path) {
  117. if (!$man->verifyPath($path))
  118. continue;
  119. $file = $man->getFile($path);
  120. if (!$file->exists()) {
  121. $this->_removeFavorite($man, $path);
  122. continue;
  123. }
  124. if ($man->verifyFile($file) < 0)
  125. continue;
  126. if ($filter->accept($file) == BASIC_FILEFILTER_ACCEPTED)
  127. $files[] = $file;
  128. }
  129. return $files;
  130. }
  131. function _getCookieData($type) {
  132. if (isset($_COOKIE["MCManagerHistoryCookie_". $type]))
  133. return $_COOKIE["MCManagerHistoryCookie_". $type];
  134. else
  135. return "";
  136. }
  137. function _removeFavorite(&$man, $path=array()) {
  138. $type = $man->getType();
  139. $cookievalue = $this->_getCookieData($type);
  140. $patharray = array();
  141. $patharray = split(",", $cookievalue);
  142. $break = false;
  143. if (count($patharray) > 0) {
  144. for($i=0;$i<count($patharray);$i++) {
  145. if (is_array($path)) {
  146. if (in_array($patharray[$i], $path))
  147. $break = true;
  148. } else {
  149. if ($patharray[$i] == $path)
  150. $break = true;
  151. }
  152. if ($break) {
  153. array_splice($patharray, $i, 1);
  154. break;
  155. }
  156. }
  157. }
  158. $cookievalue = implode(",", $patharray);
  159. $this->_setCookieData($type, $cookievalue);
  160. return true;
  161. }
  162. function _setCookieData($type, $val) {
  163. setcookie("MCManagerHistoryCookie_". $type, $val, time()+(3600*24*30)); // 30 days
  164. }
  165. }
  166. // Add plugin to MCManager
  167. $man->registerPlugin("history", new Moxiecode_HistoryPlugin());
  168. ?>