Advertisement:
GCWebhosting

Author Topic: A list of attached files...  (Read 2728 times)

Offline diegolyanky

  • Jr. Member
  • **
  • Posts: 329
  • Gender: Male
A list of attached files...
« on: November 11, 2018, 06:03:59 PM »
Hi all:

I'm trying to make a MOD wich allow to have a list of attached files...

Is this ok ? I made this MOD (see attached file), install without error, but I have no results on the list. This mod, make a new template wit the $result of query.

I don't understand at all 2.0.x ... I know only 1.1.x smf versions.

Can anyone help me ? :)

Thanks a lot !
SMF ... SimpleMachines ... Simple, but complete if you want it ;)

Online SychO

  • Lead Customizer
  • SMF Hero
  • *
  • Posts: 1,420
  • Gender: Male
    • SychO9 on GitHub
    • SychO
Re: A list of attached files...
« Reply #1 on: November 12, 2018, 05:32:29 PM »
I haven't looked at the code, but why is there a .mod file ? its contents should be made into a .xml file with operations just like the other two

Imazighen

Offline vbgamer45

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 21,401
    • smfhacks on Facebook
    • VBGAMER45 on GitHub
    • @createaforum on Twitter
    • SMF For Free
Re: A list of attached files...
« Reply #2 on: November 12, 2018, 05:33:36 PM »
.mod is the older package format is plain text format.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Online SychO

  • Lead Customizer
  • SMF Hero
  • *
  • Posts: 1,420
  • Gender: Male
    • SychO9 on GitHub
    • SychO
Re: A list of attached files...
« Reply #3 on: November 12, 2018, 05:37:48 PM »
I see, 1.x I assume, old indeed

Imazighen

Offline diegolyanky

  • Jr. Member
  • **
  • Posts: 329
  • Gender: Male
Re: A list of attached files...
« Reply #4 on: November 12, 2018, 05:57:32 PM »
.mod is the older package format is plain text format.

I see, 1.x I assume, old indeed


That's right. That's old indeed... This is the new one, under plain text format ( xml )

I tryed, and changed many query strings, by modifying to db_query ==>  $ smcFunc ['db_query'] ... and others like

mysql_fetch_assoc   ( now is $smcFunc ['db_fetch_assoc'] )
mysql_fetch_row   (now is $smcFunc ['db_fetch_row'] )

But, I don't understand how to call to a subtemplate... My brain will explode !! ...


I'm learning everything about the smf 2.x branch ... Reading all tutorial I find, as well as the smf wiki of developers

Here, I attach the modified file ...
Could someone please help me and tell me what I'm doing wrong here?

Many thanks in advance for helping me.

SMF ... SimpleMachines ... Simple, but complete if you want it ;)

Online SychO

  • Lead Customizer
  • SMF Hero
  • *
  • Posts: 1,420
  • Gender: Male
    • SychO9 on GitHub
    • SychO
Re: A list of attached files...
« Reply #5 on: November 12, 2018, 06:02:57 PM »
I don't know about 1.x, but there is no browse_special sub template in the ManageAttachements Template file in 2.0

Imazighen

Offline diegolyanky

  • Jr. Member
  • **
  • Posts: 329
  • Gender: Male
Re: A list of attached files...
« Reply #6 on: November 12, 2018, 06:19:23 PM »
I don't know about 1.x, but there is no browse_special sub template in the ManageAttachements Template file in 2.0


In 1.x either... It's supposed that template will be created by the mod.



SMF ... SimpleMachines ... Simple, but complete if you want it ;)

Online SychO

  • Lead Customizer
  • SMF Hero
  • *
  • Posts: 1,420
  • Gender: Male
    • SychO9 on GitHub
    • SychO
Re: A list of attached files...
« Reply #7 on: November 13, 2018, 11:14:34 AM »
Right, it is created by the mod, instead of using $boarddir/Themes/default/ManageAttachments.template.php you can just use $themedir/ManageAttachments.template.php, also there is a syntax error with your code

syntax error, unexpected 'else' (T_ELSE)

Imazighen

Offline diegolyanky

  • Jr. Member
  • **
  • Posts: 329
  • Gender: Male
Re: A list of attached files...
« Reply #8 on: November 13, 2018, 12:41:38 PM »
Thanks SychO ...

Yes, me too see that error.

I can't find where is the error...

Do you think it's a permissions issue ? ...

Nice themes are you developing  ;)
SMF ... SimpleMachines ... Simple, but complete if you want it ;)

Online SychO

  • Lead Customizer
  • SMF Hero
  • *
  • Posts: 1,420
  • Gender: Male
    • SychO9 on GitHub
    • SychO
Re: A list of attached files...
« Reply #9 on: November 13, 2018, 02:29:26 PM »
permissions ? No

you are adding two functions inside of a function, you have to change the position after to before
Code: [Select]
<search position="after"><![CDATA[
$_SESSION['attachments_to_fix'] = $to_fix;
$_SESSION['attachments_to_fix2'] = $context['repair_errors'];

obExit();
}]]></search>
Code: [Select]
<search position="before"><![CDATA[
$_SESSION['attachments_to_fix'] = $to_fix;
$_SESSION['attachments_to_fix2'] = $context['repair_errors'];

obExit();
}]]></search>

Imazighen

Offline diegolyanky

  • Jr. Member
  • **
  • Posts: 329
  • Gender: Male
Re: A list of attached files...
« Reply #10 on: November 13, 2018, 02:57:15 PM »
SychO:

Thanks for your reply ...

But, I tried that ... Also i'm getting same error

syntax error, unexpected 'user' (T_STRING), expecting ',' or ')'


Another idea ? ... It appears to be bad closed the function, but I can't see the error ... ( need a new brain lol )
SMF ... SimpleMachines ... Simple, but complete if you want it ;)

Online SychO

  • Lead Customizer
  • SMF Hero
  • *
  • Posts: 1,420
  • Gender: Male
    • SychO9 on GitHub
    • SychO
Re: A list of attached files...
« Reply #11 on: November 13, 2018, 03:16:43 PM »
You just need to add a closing curly bracket for the second function

Imazighen

Offline diegolyanky

  • Jr. Member
  • **
  • Posts: 329
  • Gender: Male
Re: A list of attached files...
« Reply #12 on: November 13, 2018, 03:30:50 PM »
You just need to add a closing curly bracket for the second function

 :o Where ? ...

The two functions, has its opening and closing bracket.
Or am I seeing wrong?

Where do you see that ? ...
SMF ... SimpleMachines ... Simple, but complete if you want it ;)

Online SychO

  • Lead Customizer
  • SMF Hero
  • *
  • Posts: 1,420
  • Gender: Male
    • SychO9 on GitHub
    • SychO
Re: A list of attached files...
« Reply #13 on: November 13, 2018, 03:55:54 PM »
...

Code: [Select]
<add><![CDATA[function BrowseAttachments()
{
global $context, $smcFunc, $txt, $scripturl, $options, $modSettings, $user_info;

//Let's see who is allowed to see the list?
//No Guests :P
if($context['user']['is_guest'])
redirectexit();
   //Okay now let's work a little bit :x
else {
//Admins are everytime allowed :P
if(!$context['user']['is_admin']) {
if(empty($modSettings['Allowed_Attachments_Groups']))
redirectexit();
else {
//Clean the ModSettings i will only numbers and ,
preg_match_all('/(?:([0-9,]+)|.)/i', $modSettings['Allowed_Attachments_Groups'], $matches);
$allow_array = implode('', $matches['1']);
$allow_array = explode(',', $allow_array);
if(empty($allow_array))
redirectexit();
else {
$noredirect = FALSE;
//Huf why could it not simpler, i hate it.
foreach($allow_array as $gid) {
$noredirect = in_array($gid, $user_info['groups']);
if($noredirect) break;
}
//Okay he or she is not in the Allowed Groups... go back to the index :P
if(!$noredirect)
redirectexit();
}
}
}
}

//Language
loadLanguage('Admin');

//Need to Check something
$_REQUEST['sa'] = empty($_REQUEST['sa']) ? '' : $_REQUEST['sa'];

//Okay did you Serach something? Prepare and Redirect!
if(!empty($_REQUEST['search'])) {
$context['search'] = strtolower(trim(preg_replace('~&amp;#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', htmlspecialchars($_REQUEST['search']))));
$context['search'] = addslashes($context['search']);

//Okay i simple encode it :) better browser compatible!
$context['hidden_search'] = base64_encode($context['search']);

//Okay go to the serach :x
redirectexit("action=BrowseAttachments;search2=".$context['hidden_search'] . (isset($_REQUEST['searchoption']) ? ';'.$_REQUEST['searchoption'] : ''));
}

//The Real Search is now working?
elseif(!empty($_GET['search2'])) {
SearchFiles();
}

//Okay only Browsing the files xD
else {
//Load the Attachements :P
BrowseFiles();

    //Creat a new Page Index!
$context['page_index'] = constructPageIndex($scripturl . '?action=BrowseAttachments' . ($context['browse_type'] == 'attachments' ? '' : ';' . $context['browse_type']) . ';sort=' . $context['sort_by'] . ($context['sort_direction'] == 'down' ? ';desc' : ''), $_REQUEST['start'], $context['num_' . $context['browse_type']], $modSettings['defaultMaxMessages']);
$context['sub_template'] = 'browse_special';
}

//Finish it!
loadTemplate('ManageAttachments');
}

function SearchFiles()
{
global $context, $smcFunc, $txt, $scripturl, $options, $modSettings;

$context['page_title'] = $txt['attachments_avatars'];
$context['description'] = $txt['smf202'];
$context['selected'] = 'search';
$context['sub_template'] = 'browse_special';

// Attachments or avatars?
$context['browse_type'] = 'attachments';

// Some preparing ;)
if(!empty($_REQUEST['search2'])) {
$context['search'] = base64_decode($_REQUEST['search2']);
$context['hidden_search'] = $_REQUEST['search2'];
}
else {
redirectexit("action=BrowseAttachments");
}

$context['search_option'] = (isset($_REQUEST['each']) ? 'each' : isset($_REQUEST['word']) ? 'word' : '');

//Okay you want to search each splited word... (Huge...)
if(isset($_REQUEST['each'])) {
$index = split(" ", $context['search']);
$index = array_unique($index);
reset($index);
//Okay lets generate the like index :P
$context['search_query_standard'] = "
filename LIKE '%".implode("%'
AND filename LIKE '%", $index)."%'";
$context['search_query_standard_a'] = "
a.filename LIKE '%".implode("%'
AND a.filename LIKE '%", $index)."%'";
}
elseif(isset($_REQUEST['word'])) {
$index = split(" ", $context['search']);
$index = array_unique($index);
reset($index);
//Okay lets generate the like index :P
$context['search_query_standard'] = "
(filename LIKE '%".implode("%'
OR filename LIKE '%", $index)."%')";
$context['search_query_standard_a'] = "
(a.filename LIKE '%".implode("%'
OR a.filename LIKE '%", $index)."%')";
}
else {
$context['search_query_standard'] = "filename LIKE '%".$context['search']."%'";
$context['search_query_standard_a'] = "a.filename LIKE '%".$context['search']."%'";
}

if ($browse_type === 'avatars')
$request = $smcFunc['db_query']('', '
SELECT COUNT(*)
FROM {db_prefix}attachments
WHERE id_member != {int:guest_id_member}',
array(
'guest_id_member' => 0,
)
)
else {
$request = $smcFunc['db_query']('', '
SELECT COUNT(*) AS num_attach
FROM {db_prefix}attachments AS a
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg)
INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
INNER JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg)
WHERE a.attachment_type = {int:attachment_type}
AND a.id_member = {int:guest_id_member}',
array(
'attachment_type' => $browse_type === 'thumbs' ? '3 : '0',
'guest_id_member' => 0,
)
);
}

list ($num_files) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);

return $num_files;

// Also get the avatar amount.
$request = $smcFunc['db_query']('', '
SELECT COUNT(id_attach)
FROM {db_prefix}attachments
WHERE id_member != 0
AND $context[search_query_standard]',
);
$smcFunc['db_free_result']($request);

// Allow for sorting of each column...
$sort_methods = array(
'name' => 'a.filename',
'date' => $context['browse_type'] == 'avatars' ? 'mem.last_Login' : 'm.id_msg',
'size' => 'a.size',
'member' => 'mem.real_name'
);

// Set up the importantant sorting variables... if they picked one...
if (!isset($_GET['sort']) || !isset($sort_methods[$_GET['sort']]))
{
$_GET['sort'] = 'date';
$descending = !empty($options['view_newest_first']);
}
// ... and if they didn't...
else {
$descending = isset($_GET['desc']);
}
$context['sort_by'] = $_GET['sort'];
$_GET['sort'] = $sort_methods[$_GET['sort']];
$context['sort_direction'] = $descending ? 'down' : 'up';

// Get the page index ready......
if (!isset($_REQUEST['start']) || $_REQUEST['start'] < 0)
$_REQUEST['start'] = 0;

$context['page_index'] = constructPageIndex($scripturl . '?action=BrowseAttachments;search2=' . $context['hidden_search'] . (!empty($context['search_option']) ? ';'.$context['search_option'] : '') . ';sort=' . $context['sort_by'] . ($context['sort_direction'] == 'down' ? ';desc' : ''), $_REQUEST['start'], $context['num_' . $context['browse_type']], $modSettings['defaultMaxMessages']);
$context['start'] = $_REQUEST['start'];

// Choose a query depending on what we are viewing.
if ($context['browse_type'] == 'avatars')
$request = $smcFunc['db_query']('', '
SELECT
'' AS id_msg, IFNULL(mem.real_Name, '$txt['not_applicable']') AS poster_Name, mem.last_Login AS poster_time, 0 AS ID_TOPIC, a.id_member,
a.ID_ATTACH, a.filename, a.attachment_Type, a.size, a.width, a.height, a.downloads, '' AS subject, 0 AS ID_BOARD
FROM {db_prefix}attachments AS a
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = a.id_member)
WHERE a.id_member != 0
AND $context[search_query_standard_a]
ORDER BY $_GET[sort] ' . ($descending ? 'DESC' : 'ASC') . '
LIMIT $context[start], $modSettings[defaultMaxMessages]',
);
else {
$request = $smcFunc['db_query']('', '
SELECT
m.id_msg, IFNULL(mem.real_Name, m.poster_Name) AS poster_Name, m.poster_time, m.ID_TOPIC, m.id_member,
a.ID_ATTACH, a.filename, a.attachment_Type, a.size, a.width, a.height, a.downloads, mf.subject, t.ID_BOARD
FROM ({db_prefix}attachments AS a, {db_prefix}messages AS m, {db_prefix}topics AS t, {db_prefix}messages AS mf)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
WHERE a.id_msg = m.id_msg
AND a.attachment_Type = ' . ($context['browse_type'] == 'attachments' ? '0' : '3') . '
AND t.ID_TOPIC = m.ID_TOPIC
AND mf.id_msg = t.ID_FIRST_MSG
AND $context[search_query_standard_a]
ORDER BY $_GET[sort] ' . ($descending ? 'DESC' : 'ASC') . '
LIMIT $context[start], $modSettings[defaultMaxMessages]',
);
}

$context['posts'] = array();
while ($row = $smcFunc['db_fetch_assoc'] ($result))
$context['posts'][] = array(
'id' => $row['id_msg'],
'poster' => array(
'id' => $row['id_member'],
'name' => $row['poster_Name'],
'href' => empty($row['id_member']) ? '' : $scripturl . '?action=profile;u=' . $row['id_member'],
'link' => empty($row['id_member']) ? $row['poster_Name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_Name'] . '</a>'
),
'time' => empty($row['poster_time']) ? $txt['never'] : timeformat($row['poster_time']),
'timestamp' => forum_time(true, $row['poster_time']),
'attachment' => array(
'id' => $row['ID_ATTACH'],
'size' => $_FILES['attachment']['size'][$n],
'width' => $row['width'],
'height' => $row['height'],
'name' => $_FILES['attachment']['name'][$n],
'downloads' => $row['downloads'],
'href' => $row['attachment_Type'] == 1 ? $modSettings['custom_avatar_url'] . '/' . $row['filename'] : ($scripturl . '?action=dlattach;' . ($context['browse_type'] == 'avatars' ? 'type=avatar;' : 'topic=' . $row['ID_TOPIC'] . '.0;') . 'id=' . $row['ID_ATTACH']),
'link' => '<a href="' . ($row['attachment_Type'] == 1 ? $modSettings['custom_avatar_url'] . '/' . $row['filename'] : ($scripturl . '?action=dlattach;' . ($context['browse_type'] == 'avatars' ? 'type=avatar;' : 'topic=' . $row['ID_TOPIC'] . '.0;') . 'id=' . $row['ID_ATTACH'])) . '"' . (empty($row['width']) || empty($row['height']) ? '' : ' onclick="return reqWin(this.href + \';image\', ' . ($row['width'] + 20) . ', ' . ($row['height'] + 20) . ', true);"') . '>' . $row['filename'] . '</a>'
),
'topic' => $row['ID_TOPIC'],
'subject' => $row['subject'],
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0">' . $row['subject'] . '</a>'
);

$smcFunc['db_free_result']($request);]]></add>
^^^^ here

Imazighen

Offline diegolyanky

  • Jr. Member
  • **
  • Posts: 329
  • Gender: Male
Re: A list of attached files...
« Reply #14 on: November 13, 2018, 04:13:34 PM »
SychO:

I do not know what happened ... Maybe, I confused the file I uploaded.
Here is the correct one, and it has the close brackets in its places.

Sorry for that...

Likewise, it does not work and still giving same error.

Code: [Select]

syntax error, unexpected 'user' (T_STRING), expecting ',' or ')'


No errors on Log Error Admin section...

Maybe, I'm calling any property of 'user' with error ?

Why expecting ',' or ')'   ?

SMF ... SimpleMachines ... Simple, but complete if you want it ;)

Online SychO

  • Lead Customizer
  • SMF Hero
  • *
  • Posts: 1,420
  • Gender: Male
    • SychO9 on GitHub
    • SychO
Re: A list of attached files...
« Reply #15 on: November 13, 2018, 04:29:30 PM »
It's just a syntax error, you probably missed a semicolon or something somewhere


Imazighen

Offline Shambles

  • SMF Hero
  • ******
  • Posts: 5,145
  • Gender: Male
    • i30 Owners Club
Re: A list of attached files...
« Reply #16 on: November 13, 2018, 04:32:14 PM »
Copy & Paste your code blocks to a parsing website like https://www.piliapp.com/php-syntax-check/

Offline diegolyanky

  • Jr. Member
  • **
  • Posts: 329
  • Gender: Male
Re: A list of attached files...
« Reply #17 on: November 13, 2018, 04:42:36 PM »
Copy & Paste your code blocks to a parsing website like https://www.piliapp.com/php-syntax-check/

Sh@mbles ... Thanks for reply. I did it many times and no error found. Tried on piliapp - stackoverflow - and other sites with a php parsers

For that reason, I think it's a variable or a function specific of SMF 2.0 wich I don't understand yet.


It's just a syntax error, you probably missed a semicolon or something somewhere


Thanks again ... Yeah, I thinked about a semicolon or something simple but I can't find it !

SMF ... SimpleMachines ... Simple, but complete if you want it ;)

Offline diegolyanky

  • Jr. Member
  • **
  • Posts: 329
  • Gender: Male
Re: A list of attached files...
« Reply #18 on: November 13, 2018, 04:46:11 PM »
SychO:

I do not know what happened ... Maybe, I confused the file I uploaded.
Here is the correct one, and it has the close brackets in its places.


SMF ... SimpleMachines ... Simple, but complete if you want it ;)

Offline Rock Lee

  • Native Language Support Specialist
  • SMF Hero
  • *
  • Posts: 2,836
  • Gender: Male
  • I also speak english :D
    • BomberCode.Oficial on Facebook
    • RockLee-BC on GitHub
    • @Bomber_Code on Twitter
    • Bomber Code ~ La nueva era del conocimiento
Re: A list of attached files...
« Reply #19 on: November 13, 2018, 07:29:19 PM »
I have some doubts about the issue of permits but it would work fairly as it should.


Regards!
¡Regresando como cual Fenix! ~ Bomber Code © 2018
Ayudas - Aportes - Tutoriales - Y mucho mas!!!


Ayudame via PayPal