Modifying the plugin to "insert file list in content" to show file size
-
- Phoca Member
- Posts: 17
- Joined: 10 May 2013, 18:41
Modifying the plugin to "insert file list in content" to show file size
Hello !
First, i search and try a lot before posting here but i did not find a solution.
I would like to have the file size shown when i use the plugin button in content.
To do so, i could modify the plugin code if needed but there is something i don't understand...
In the plugin code, i can see the query (file list). In the database, in the table phocadownload, i can see a field "filesize".
But in the database, this field seems to be unused : all the filesize are on 0.
I search in the phoca download code and found the function "filesize" seems to be used to show the file size when the view is called from the component view from a menu.
My question is then :
Is there somebody who could help me and provide me a code to add in the plugin code to only show beside the name of the file the size of the file ? That is something asked often but i don't find a "right" way to achieve this.
Many thanks in advance for the help !
Xavier
First, i search and try a lot before posting here but i did not find a solution.
I would like to have the file size shown when i use the plugin button in content.
To do so, i could modify the plugin code if needed but there is something i don't understand...
In the plugin code, i can see the query (file list). In the database, in the table phocadownload, i can see a field "filesize".
But in the database, this field seems to be unused : all the filesize are on 0.
I search in the phoca download code and found the function "filesize" seems to be used to show the file size when the view is called from the component view from a menu.
My question is then :
Is there somebody who could help me and provide me a code to add in the plugin code to only show beside the name of the file the size of the file ? That is something asked often but i don't find a "right" way to achieve this.
Many thanks in advance for the help !
Xavier
- Jan
- Phoca Hero
- Posts: 48550
- Joined: 10 Nov 2007, 18:23
- Location: Czech Republic
- Contact:
Re: Modifying the plugin to "insert file list in content" to show file size
Hi, as you can see in the component, the filesize is set by function:
administrator\components\com_phocadownload\libraries\phocadownload\render\layout.php (line cca 101)
It directly check the size of the original file stored on server.
Jan
Code: Select all
$l = new PhocaDownloadLayout();
$fileSize = $l->getFilesize($v->filename);
It directly check the size of the original file stored on server.
Jan
If you find Phoca extensions useful, please support the project
-
- Phoca Member
- Posts: 17
- Joined: 10 May 2013, 18:41
Re: Modifying the plugin to "insert file list in content" to show file size
Hi Jan,
I saw this line of code but i don't succeed to use it...
In the plugin code, i have added this :
I have obviously an error as i have a php error 0 raised.
Jan, can you help just for the line $fileSize = $items->getFilesize($v->filename); to help me to have the right thing ?
Thanks a lot,
Xavier
I saw this line of code but i don't succeed to use it...
In the plugin code, i have added this :
Code: Select all
ADDED at line 295
if ($text !='') {
$textOutput = $text;
} else if (isset($item->title) && $item->title != '') {
$textOutput = $item->title;
} else {
$textOutput = JText::_('PLG_CONTENT_PHOCADOWNLOAD_DOWNLOAD_FILE');
}
/*show filesize */
//$l = new PhocaDownloadLayout(); Commented as already declared at the beginning of the script
$fileSize = $items->getFilesize($->filename);
// also tried with : $fileSize = $items->getFilesize($v->filename); -> error
$textOutput .= '('. $fileSize .')';
/*end show filesize */
Jan, can you help just for the line $fileSize = $items->getFilesize($v->filename); to help me to have the right thing ?
Thanks a lot,
Xavier
- Jan
- Phoca Hero
- Posts: 48550
- Joined: 10 Nov 2007, 18:23
- Location: Czech Republic
- Contact:
Re: Modifying the plugin to "insert file list in content" to show file size
Hi, which error do you exactly get?
Jan
Jan
If you find Phoca extensions useful, please support the project
-
- Phoca Member
- Posts: 17
- Joined: 10 May 2013, 18:41
Re: Modifying the plugin to "insert file list in content" to show file size
Hi Jan,
I now have this code :
The goal is to add the size of the file with something like (xxxxxx)
This give me : 0 - Call to a member function getFilesize() on array
Thanks for the help,
Xavier
I now have this code :
Code: Select all
$fileSize = $l->getFilesize($v->filename);
$textOutput .= '('. $fileSize .')';
This give me : 0 - Call to a member function getFilesize() on array
Thanks for the help,
Xavier
- Jan
- Phoca Hero
- Posts: 48550
- Joined: 10 Nov 2007, 18:23
- Location: Czech Republic
- Contact:
Re: Modifying the plugin to "insert file list in content" to show file size
Hi, did you declare the $l variable?
$l = new PhocaDownloadLayout();
Jan
$l = new PhocaDownloadLayout();
Jan
If you find Phoca extensions useful, please support the project
-
- Phoca Member
- Posts: 17
- Joined: 10 May 2013, 18:41
Re: Modifying the plugin to "insert file list in content" to show file size
Hi Jan,
Yes i did...
Xavier
Yes i did...
Xavier
- Jan
- Phoca Hero
- Posts: 48550
- Joined: 10 Nov 2007, 18:23
- Location: Czech Republic
- Contact:
Re: Modifying the plugin to "insert file list in content" to show file size
Can you enable php error reporting:
https://www.phoca.cz/documents/16-jooml ... rs-on-site
and let me know the whole error message you get there:
https://www.phoca.cz/documents/16-jooml ... rs-on-site
and let me know the whole error message you get there:
Call to a member function getFilesize() on array
If you find Phoca extensions useful, please support the project
-
- Phoca Member
- Posts: 17
- Joined: 10 May 2013, 18:41
Re: Modifying the plugin to "insert file list in content" to show file size
Here is the full debug message :
EDIT
I also get this in another console (removed the full path from the code) :
Code: Select all
Call to a member function getFilesize() on array
/home/xxxx/public_html/xxxx/plugins/content/phocadownload/phocadownload.php:297
Call stack
# Function Location
1 () JROOT/plugins/content/phocadownload/phocadownload.php:297
2 plgContentPhocaDownload->onContentPrepare() JROOT/libraries/joomla/event/event.php:70
3 JEvent->update() JROOT/components/com_flexicontent/helpers/dispatcher.php:172
4 FCDispatcher->trigger() JROOT/components/com_flexicontent/classes/flexicontent.fields.php:1064
5 FlexicontentFields::triggerContentPlugins() JROOT/components/com_flexicontent/classes/flexicontent.fields.php:889
6 FlexicontentFields::renderField() JROOT/components/com_flexicontent/classes/flexicontent.fields.php:1142
7 FlexicontentFields::renderPositions() JROOT/components/com_flexicontent/classes/flexicontent.fields.php:164
8 FlexicontentFields::getFields() JROOT/components/com_flexicontent/views/item/view.html.php:196
9 FlexicontentViewItem->display() JROOT/libraries/src/MVC/Controller/BaseController.php:672
10 Joomla\CMS\MVC\Controller\BaseController->display() JROOT/components/com_flexicontent/controller.php:1222
11 FlexicontentController->display() JROOT/libraries/src/MVC/Controller/BaseController.php:710
12 Joomla\CMS\MVC\Controller\BaseController->execute() JROOT/components/com_flexicontent/flexicontent.php:266
13 require_once() JROOT/libraries/src/Component/ComponentHelper.php:382
14 Joomla\CMS\Component\ComponentHelper::executeComponent() JROOT/libraries/src/Component/ComponentHelper.php:357
15 Joomla\CMS\Component\ComponentHelper::renderComponent() JROOT/libraries/src/Application/SiteApplication.php:194
16 Joomla\CMS\Application\SiteApplication->dispatch() JROOT/libraries/src/Application/SiteApplication.php:233
17 Joomla\CMS\Application\SiteApplication->doExecute() JROOT/libraries/src/Application/CMSApplication.php:195
18 Joomla\CMS\Application\CMSApplication->execute() JROOT/index.php:49
I also get this in another console (removed the full path from the code) :
Code: Select all
#0 /libraries/joomla/event/event.php(70): plgContentPhocaDownload->onContentPrepare('com_content.art...', Object(stdClass), Object(Joomla\Registry\Registry), 0)
#1 /components/com_flexicontent/helpers/dispatcher.php(172): JEvent->update(Array)
#2 /components/com_flexicontent/classes/flexicontent.fields.php(1064): FCDispatcher->trigger('oncontentprepar...', Array, NULL)
#3 /components/com_flexicontent/classes/flexicontent.fields.php(889): FlexicontentFields::triggerContentPlugins(Object(stdClass), Object(stdClass), 'display', 'item', false)
#4 /components/com_flexicontent/classes/flexicontent.fields.php(1142): FlexicontentFields::renderField(Array, 'text', NULL, 'display', 'item')
#5 /components/com_flexicontent/classes/flexicontent.fields.php(164): FlexicontentFields::renderPositions(Array, 'item', Object(Joomla\Registry\Registry), true, Array)
#6 /components/com_flexicontent/views/item/view.html.php(196): FlexicontentFields::getFields(Array, 'item', Object(Joomla\Registry\Registry), Array)
#7 /libraries/src/MVC/Controller/BaseController.php(672): FlexicontentViewItem->display()
#8 /components/com_flexicontent/controller.php(1222): Joomla\CMS\MVC\Controller\BaseController->display(true, Array)
#9 /libraries/src/MVC/Controller/BaseController.php(710): FlexicontentController->display()
#10 /components/com_flexicontent/flexicontent.php(266): Joomla\CMS\MVC\Controller\BaseController->execute('')
#11 /libraries/src/Component/ComponentHelper.php(382): require_once('/home/mesjpofr/...')
#12 /libraries/src/Component/ComponentHelper.php(357): Joomla\CMS\Component\ComponentHelper::executeComponent('/home/mesjpofr/...')
#13 /libraries/src/Application/SiteApplication.php(194): Joomla\CMS\Component\ComponentHelper::renderComponent('com_flexiconten...')
#14 /libraries/src/Application/SiteApplication.php(233): Joomla\CMS\Application\SiteApplication->dispatch()
#15 /libraries/src/Application/CMSApplication.php(195): Joomla\CMS\Application\SiteApplication->doExecute()
#16 /index.php(49): Joomla\CMS\Application\CMSApplication->execute()
- Jan
- Phoca Hero
- Posts: 48550
- Joined: 10 Nov 2007, 18:23
- Location: Czech Republic
- Contact:
Re: Modifying the plugin to "insert file list in content" to show file size
Hi, the function:
public function getFileSize($filename)
gets string as parameter but seems it gets an array in your code.
Try to debug
$l->getFilesize($v->filename);
if the $v->filename is really a filename not some array
Jan
public function getFileSize($filename)
gets string as parameter but seems it gets an array in your code.
Try to debug
$l->getFilesize($v->filename);
if the $v->filename is really a filename not some array

Jan
If you find Phoca extensions useful, please support the project