A list of attached files...

Started by diegolyanky, November 11, 2018, 06:03:59 PM

Previous topic - Next topic

diegolyanky

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 ;)

SychO

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
Checkout My Themes:
-

Potato  •  Ackerman  •  SunRise  •  NightBreeze

vbgamer45

.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

SychO

Checkout My Themes:
-

Potato  •  Ackerman  •  SunRise  •  NightBreeze

diegolyanky

Quote from: vbgamer45 on November 12, 2018, 05:33:36 PM
.mod is the older package format is plain text format.

Quote from: SychO on November 12, 2018, 05:37:48 PM
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 ;)

SychO

I don't know about 1.x, but there is no browse_special sub template in the ManageAttachements Template file in 2.0
Checkout My Themes:
-

Potato  •  Ackerman  •  SunRise  •  NightBreeze

diegolyanky

Quote from: SychO 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


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



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

SychO

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)
Checkout My Themes:
-

Potato  •  Ackerman  •  SunRise  •  NightBreeze

diegolyanky

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 ;)

SychO

permissions ? No

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

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

<search position="before"><![CDATA[
$_SESSION['attachments_to_fix'] = $to_fix;
$_SESSION['attachments_to_fix2'] = $context['repair_errors'];

obExit();
}]]></search>
Checkout My Themes:
-

Potato  •  Ackerman  •  SunRise  •  NightBreeze

diegolyanky

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 ;)

SychO

You just need to add a closing curly bracket for the second function
Checkout My Themes:
-

Potato  •  Ackerman  •  SunRise  •  NightBreeze

diegolyanky

Quote from: SychO on November 13, 2018, 03:16:43 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 ;)

SychO

...

<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
Checkout My Themes:
-

Potato  •  Ackerman  •  SunRise  •  NightBreeze

diegolyanky

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.



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 ;)

SychO

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

Checkout My Themes:
-

Potato  •  Ackerman  •  SunRise  •  NightBreeze

Shambles


diegolyanky

Quote from: Sh@mbles 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/

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.


Quote from: SychO on November 13, 2018, 04:29:30 PM
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 ;)

diegolyanky

Quote from: diegolyanky 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.


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

-Rock Lee-

I have some doubts about the issue of permits but it would work fairly as it should.


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

Advertisement: