arms
Well-known member
As I'm learning by creating functionality I need, This modification may seem like a bridge too far to start but making good headway.
What I'm doing is adding another prefix to threads (They will go at end of thread title, so will be called suffixes for now,,.. basically I'm copying the prefix code and rewriting is as suffix.). I've got all the admin side working and works exactly like the standard prefix functionality.
I've added the suffix_cache, default_suffix_id & require_suffix to xf_forum.
I've added tables, xf_forum_suffix, xf_thread_suffix_group & xf_thread_suffix that mirror prefix table fields.
I've checked the phrases and when being added phrases are also being updated correctly. the forum.suffix_cache is being populated.
Problem is I can't get the helper to work correctly:
The phrase is being missed and I'm not sure if it's because my helper is wrong. The group is there and the correct css class for each is there and if I select an option, its recording in the dbase.
I can then do things like index.php?forums/more-main.7/&prefix_id=8&suffix_id=18 which works like I want.
Any real developers (basically anyone better than my half baked non skills) willing to help with this last bit? Have I missed something, is below a load of rubbish?
I've spent a fair bit of time on this and I seem to have spent most of it trying to fix this bit so any help would be appreciated.
Proxy.php
Suffix.php
What I'm doing is adding another prefix to threads (They will go at end of thread title, so will be called suffixes for now,,.. basically I'm copying the prefix code and rewriting is as suffix.). I've got all the admin side working and works exactly like the standard prefix functionality.
I've added the suffix_cache, default_suffix_id & require_suffix to xf_forum.
I've added tables, xf_forum_suffix, xf_thread_suffix_group & xf_thread_suffix that mirror prefix table fields.
I've checked the phrases and when being added phrases are also being updated correctly. the forum.suffix_cache is being populated.
Problem is I can't get the helper to work correctly:
The phrase is being missed and I'm not sure if it's because my helper is wrong. The group is there and the correct css class for each is there and if I select an option, its recording in the dbase.
I can then do things like index.php?forums/more-main.7/&prefix_id=8&suffix_id=18 which works like I want.
Any real developers (basically anyone better than my half baked non skills) willing to help with this last bit? Have I missed something, is below a load of rubbish?
I've spent a fair bit of time on this and I seem to have spent most of it trying to fix this bit so any help would be appreciated.
Code:
<option value="{$suffix.suffix_id}" data-css="{$suffix.css_class}" {xen:selected '{$selectedSuffix} == {$suffix.suffix_id}'}>{xen:helper threadSuffix, $suffix.suffix_id, escaped, ''}</option>
Proxy.php
PHP:
class PG_Suffix_Listener_Proxy
{
public static function dependencies(XenForo_Dependencies_Abstract $dependencies, array $data)
{
XenForo_Template_Helper_Core::$helperCallbacks['threadsuffix'] = array('PG_Suffix_ViewPublic_Helper_Suffix', 'helperThreadSuffix');
XenForo_Template_Helper_Core::$helperCallbacks['threadsuffixgroup'] = array('PG_Suffix_ViewPublic_Helper_Suffix', 'helperThreadSuffixGroup');
}
}
Suffix.php
PHP:
<?php
class PG_Suffix_ViewPublic_Helper_Suffix
{
protected static $_language = null;
protected static $_threadSuffixes = array();
public static function helperThreadSuffixGroup($suffixGroupId)
{
return self::_getPhraseText('thread_suffix_group_' . $suffixGroupId);
}
/**
* Helper to display a thread suffix for the specified suffix ID/thread. Can take an array.
*
* @param integer|array $suffixId Suffix ID or array with key of suffix_id
* @param string $outputType Type of output; options are html (marked up), plain (plain text), escaped (plain text escaped)
* @param string|null $append Value to append if there is a suffix (eg, a space); if null, defaults to space (html) or dash (plain)
*
* @return string
*/
public static function helperThreadSuffix($suffixId, $outputType = 'html', $append = null)
{
if (is_array($suffixId))
{
if (!isset($suffixId['suffix_id']))
{
return '';
}
$suffixId = $suffixId['suffix_id'];
}
$suffixId = intval($suffixId);
if (!$suffixId || !isset(self::$_threadSuffixes[$suffixId]))
{
return '';
}
$text = self::_getPhraseText('thread_suffix_' . $suffixId);
if ($text === '')
{
return '';
}
switch ($outputType)
{
case 'html':
$text = '<span class="' . htmlspecialchars(self::$_threadSuffixes[$suffixId]) . '">'
. htmlspecialchars($text) . '</span>';
if ($append === null)
{
$append = ' ';
}
break;
case 'plain':
break; // ok as is
default:
$text = htmlspecialchars($text); // just be safe and escape everything else
}
if ($append === null)
{
$append = ' - ';
}
return $text . $append;
}
/**
* Fetches the text of the specified phrase
*
* @param string $phraseName
*
* @return string
*/
protected static function _getPhraseText($phraseName)
{
if (self::$_language && isset(self::$_language['phrase_cache']))
{
$cache = self::$_language['phrase_cache'];
return (isset($cache[$phraseName]) ? $cache[$phraseName] : '');
}
else
{
$phrase = new XenForo_Phrase($phraseName);
return $phrase->render(false);
}
}
/**
* Sets the thread suffixes.
*
* @param array $suffixes [suffix id] => class name
*/
public static function setThreadSuffixes($suffixes)
{
self::$_threadSuffixes = $suffixes;
}
}
Last edited: