@@ -40,17 +40,101 @@ public function __construct()
4040 );
4141 }
4242
43+ /**
44+ * Return files
45+ *
46+ * @param string $path Parent directory path
47+ * @param string $type Type of storage, e.g. image, media etc.
48+ * @return Varien_Data_Collection_Filesystem
49+ */
50+ public function getFilesCollection ($ path , $ type = null )
51+ {
52+ if (!$ this ->_configuration ->isEnabled ()) {
53+ return parent ::getFilesCollection ($ path , $ type );
54+ }
55+
56+ if (Mage::helper ('core/file_storage_database ' )->checkDbUsage ()) {
57+ $ files = Mage::getModel ('core/file_storage_database ' )->getDirectoryFiles ($ path );
58+
59+ $ fileStorageModel = Mage::getModel ('core/file_storage_file ' );
60+ foreach ($ files as $ file ) {
61+ $ fileStorageModel ->saveFile ($ file );
62+ }
63+ }
64+
65+ $ collection = $ this ->getCollection ($ path )
66+ ->setCollectDirs (false )
67+ ->setCollectFiles (true )
68+ ->setCollectRecursively (false )
69+ ->setOrder ('mtime ' , Varien_Data_Collection::SORT_ORDER_ASC );
70+
71+ // Add files extension filter
72+ if ($ allowed = $ this ->getAllowedExtensions ($ type )) {
73+ $ collection ->setFilesFilter ('/\.( ' . implode ('| ' , $ allowed ). ')$/i ' );
74+ }
75+
76+ $ helper = $ this ->getHelper ();
77+
78+ // prepare items
79+ foreach ($ collection as $ item ) {
80+ $ item ->setId ($ helper ->idEncode ($ item ->getBasename ()));
81+ $ item ->setName ($ item ->getBasename ());
82+ $ item ->setShortName ($ helper ->getShortFilename ($ item ->getBasename ()));
83+ $ item ->setUrl ($ helper ->getCurrentUrl () . $ item ->getBasename ());
84+
85+ if ($ this ->isImage ($ item ->getBasename ())) {
86+ $ thumbUrl = $ this ->getThumbnailUrl (
87+ Mage_Core_Model_File_Uploader::getCorrectFileName ($ item ->getFilename ()),
88+ true ,
89+ $ item ->getFilename ()
90+ );
91+ // generate thumbnail "on the fly" if it does not exists
92+ if (! $ thumbUrl ) {
93+ $ thumbUrl = Mage::getSingleton ('adminhtml/url ' )->getUrl ('*/*/thumbnail ' , array ('file ' => $ item ->getId ()));
94+ }
95+
96+ $ size = @getimagesize ($ item ->getFilename ());
97+
98+ if (is_array ($ size )) {
99+ $ item ->setWidth ($ size [0 ]);
100+ $ item ->setHeight ($ size [1 ]);
101+ }
102+ } else {
103+ $ thumbUrl = Mage::getDesign ()->getSkinBaseUrl () . self ::THUMB_PLACEHOLDER_PATH_SUFFIX ;
104+ }
105+
106+ $ item ->setThumbUrl ($ thumbUrl );
107+ }
108+
109+ return $ collection ;
110+ }
111+
43112 /**
44113 * @param string $filePath
45114 * @param bool $checkFile
46115 * @return string
47116 */
48- public function getThumbnailUrl ($ filePath , $ checkFile = false )
117+ public function getThumbnailUrl ($ filePath , $ checkFile = false , $ origFilePath = null )
49118 {
119+ $ _origUrl = $ origUrl = parent ::getThumbnailUrl ($ filePath , $ checkFile );
120+
121+ if (!$ this ->_configuration ->isEnabled ()) {
122+ return $ _origUrl ;
123+ }
124+
125+ if (!$ _origUrl && !is_null ($ origFilePath )) {
126+ $ filePath = $ origFilePath ;
127+ $ origUrl = parent ::getThumbnailUrl ($ filePath , $ checkFile );
128+ }
129+
130+ if (!$ origUrl ) {
131+ return $ _origUrl ;
132+ }
133+
50134 $ image = $ this ->_imageFactory ->build (
51135 $ filePath ,
52- function () use ( $ filePath , $ checkFile ) {
53- return parent :: getThumbnailUrl ( $ filePath , $ checkFile ) ;
136+ function () use ( $ _origUrl ) {
137+ return ( string ) $ _origUrl ;
54138 }
55139 );
56140
@@ -71,7 +155,7 @@ function() use($filePath, $checkFile) {
71155 public function uploadFile ($ targetPath , $ type = null )
72156 {
73157 if (!$ this ->_configuration ->isEnabled ()) {
74- return parent ::uploadFile ($ targetPath , $ type );
158+ return parent ::uploadFile ($ targetPath , $ type );
75159 }
76160
77161 $ uploader = new Cloudinary_Cloudinary_Model_Cms_Uploader ('image ' );
0 commit comments