Customizable entry order

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
TheSHEEEP
Regular
Posts: 16
Joined: Tue Dec 07, 2010 6:44 pm
Location: Berlin

Customizable entry order

Post by TheSHEEEP »

Hey there,

I know that there is a plugin where you can set the orders ascending or descending, based on the date, but what I want is to give each entry an individual "sorting priority" (best place would be in the "edit entry" page), and then sort the entries in a category according to that variable when viewing it.

Probably by directly editing the entries.tpl. I already did that a few times, without really knowing anything about tpl, php, js. Well, what I did was removing code from it to have a more clean look.

The question: How could I do such a thing?
I assume a plugin would be in order, but since I've never written one, I'm a bit lost here :)
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Customizable entry order

Post by garvinhicking »

Hi!

That's pretty advanced. But you can add a entryproperty field where you enter numbers for sorting priority, and then in the default sorting order you could order by "ep.yourfieldname ASC/DESC" to order by that field.

However, this is really against blog standards. You might want to think if either a static page with individual listing or a CMS is not better suited for your usage scenario...else you're diving deep into things that are greatly possible with s9y, but require coding skills...

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
TheSHEEEP
Regular
Posts: 16
Joined: Tue Dec 07, 2010 6:44 pm
Location: Berlin

Re: Customizable entry order

Post by TheSHEEEP »

Yeah, this surely is against blog standards.
But what I'm doing is more of a homepage than a blog, made with s9y.

And coding skills I do have, just not in php/databases/javascript. But you have to start somewhere, I guess.

So, I'll just start figuring out how to add an entry property (shouldn't be that hard, eh?) and then report back. ;)
TheSHEEEP
Regular
Posts: 16
Joined: Tue Dec 07, 2010 6:44 pm
Location: Berlin

Re: Customizable entry order

Post by TheSHEEEP »

Alright, here is what I achieved so far:

I took the entryproperties plugin and based my own one on that. I tried to remove everything where I could guess that it was not needed in my plugin and left everything else in.

The result is that each entry now has an additional textbox that belongs to the plugin. In this textbox you can write the priority and it is saved and restored when you revisit the entry.
This is good (and actually far more than I thought I could achieve in some hours).

But many questions remain:

1. The textbox with a description appears below the entry AND in the plugin configuration. I don't want anything to appear in the plugin configuration or at least something else (like a default priority). How can I do that?

2. You can actually write anything into the priority. I want only numbers to be possible. I used add('type', 'string'), is there a 'int' or 'numbers' type?

3. Below is the code of the plugin. It would be very nice if someone could tell me what I can throw out of the plugin. I guess that many things that I kept from the entryproperties plugin are completely unneccessary here, but due to my limited experience with s9y and DBs, I have no idea.

Code: Select all

class serendipity_event_customsortingorder extends serendipity_event
{
    var $services, $showPasswordForm;
    var $title = PLUGIN_EVENT_CUSTOMSORTINGORDER_TITLE;

    function introspect(&$propbag)
    {
        global $serendipity;

        $propbag->add('name',          PLUGIN_EVENT_CUSTOMSORTINGORDER_TITLE);
        $propbag->add('description',   PLUGIN_EVENT_CUSTOMSORTINGORDER_DESC);
        $propbag->add('stackable',     false);
        $propbag->add('author',        'Jan D');
        $propbag->add('version',       '0.1');
        $propbag->add('requirements',  array(
            'serendipity' => '0.8',
            'smarty'      => '2.6.7',
            'php'         => '4.1.0'
        ));
        $propbag->add('event_hooks',    array(
            'frontend_fetchentries'                             => true,
            'frontend_fetchentry'                               => true,
            'backend_publish'                                   => true,
            'backend_save'                                      => true,
            'backend_display'                                   => true,
            'backend_import_entry'                              => true,
            'entry_display'                                     => true,
            'frontend_entryproperties'                          => true,
            'backend_plugins_new_instance'                      => true,
            'backend_entry_presave'                             => true,
            'frontend_configure'                                => true
        ));
        $propbag->add('groups', array('BACKEND_EDITOR'));
        $propbag->add('configuration', array('sorting_priority'));
    }

    function introspect_config_item($name, &$propbag)
    {
        switch($name) {
            case 'sorting_priority':
                $propbag->add('type',        'string');
                $propbag->add('name',        PLUGIN_EVENT_CUSTOMSORTINGORDER_PRIORITY);
                $propbag->add('description', PLUGIN_EVENT_CUSTOMSORTINGORDER_PRIORITY_DESC);
                $propbag->add('default',     '0');
                break;
        }
        return true;
    }

    function generate_content(&$title) {
        $title = $this->title;
    }

    function install() {
        serendipity_plugin_api::hook_event('backend_cache_entries', $this->title);
    }

    function uninstall() {
        serendipity_plugin_api::hook_event('backend_cache_purge', $this->title);
    }

    function &getValidAuthors() {
        global $serendipity;

        if (serendipity_checkPermission('adminUsersMaintainOthers')) {
            $users = serendipity_fetchUsers('');
        } elseif (serendipity_checkPermission('adminUsersMaintainSame')) {
            $users = serendipity_fetchUsers('', serendipity_getGroups($serendipity['authorid'], true));
        } else {
            $users = serendipity_fetchUsers($serendipity['authorid']);
        }

        return $users;
    }

    function getSupportedProperties() {
        static $supported_properties = null;

        if ($supported_properties === null) {
            $supported_properties = array('sorting_priority');
        }

        return $supported_properties;
    }

    function returnQueryCondition($is_cache) {
        $and = '';
        if (!$is_cache) {
            $and = " AND property NOT LIKE 'ep_cache_%' ";
        }

        return $and;
    }

    /*
     * This function converts specific property fields so that they are
     * available natively to other plugins/templates.
     */
    function applyProperties(&$properties) {
        global $serendipity;

        if (is_array($properties['disable_markups'])) {
            foreach($properties['disable_markups'] AS $idx => $instance) {
                $properties['disable_markup_' . $instance] = $instance;
            }
        }
    }

    function addProperties(&$properties, &$eventData) {
        global $serendipity;
        // Get existing data
        $property = serendipity_fetchEntryProperties($eventData['id']);
        $supported_properties = serendipity_event_entryproperties::getSupportedProperties();

        // Special case for disable markups.
        if (is_array($properties['disable_markups'])) {
            $q = "DELETE FROM {$serendipity['dbPrefix']}entryproperties WHERE entryid = " . (int)$eventData['id'] . " AND property LIKE 'ep_disable_markup_%'";
            serendipity_db_query($q);

            foreach($properties['disable_markups'] AS $idx => $instance) {
                $supported_properties[] = 'disable_markup_' . $instance;
            }
        }

        serendipity_plugin_api::hook_event('backend_entryproperties', $supported_properties);

        foreach($supported_properties AS $prop_key) {
            $prop_val = (isset($properties[$prop_key]) ? $properties[$prop_key] : null);
            $prop_key = 'ep_' . $prop_key;

            if (is_array($prop_val)) {
                $prop_val = ";" . implode(';', $prop_val) . ";";
            }

            $q = "DELETE FROM {$serendipity['dbPrefix']}entryproperties WHERE entryid = " . (int)$eventData['id'] . " AND property = '" . serendipity_db_escape_string($prop_key) . "'";
            serendipity_db_query($q);

            if (!empty($prop_val)) {
                $q = "INSERT INTO {$serendipity['dbPrefix']}entryproperties (entryid, property, value) VALUES (" . (int)$eventData['id'] . ", '" . serendipity_db_escape_string($prop_key) . "', '" . serendipity_db_escape_string($prop_val) . "')";
                serendipity_db_query($q);
            }
        }
    }

    function event_hook($event, &$bag, &$eventData, $addData = null) {
        global $serendipity;

        $hooks = &$bag->get('event_hooks');

        if (isset($hooks[$event])) {
            switch($event) {

                case 'backend_display':

                    if (isset($eventData['properties']['ep_sorting_priority'])) {
                        $sorting_priority = $eventData['properties']['ep_sorting_priority'];
                    } elseif (isset($serendipity['POST']['properties']['sorting_priority'])) {
                        $sorting_priority = $serendipity['POST']['properties']['sorting_priority'];
                    } else {
                        $sorting_priority = $this->get_config('sorting_priority', '0');
                    }

?>
                    <fieldset style="margin: 5px" class="entryproperties">
                        <legend><?php echo PLUGIN_EVENT_CUSTOMSORTINGORDER_TITLE; ?></legend>
                        <div class="entryproperties_sorting_priority">
                            <input class="input_textbox" type="text" name="serendipity[properties][sorting_priority]" id="properties_sorting_priority" value="<?php echo $sorting_priority?>"/>
                                <label title="<?php echo PLUGIN_EVENT_CUSTOMSORTINGORDER_PRIORITY; ?>" for="properties_is_sticky">&nbsp;<?php echo PLUGIN_EVENT_CUSTOMSORTINGORDER_PRIORITY_DESC; ?>&nbsp;&nbsp;</label>
                        </div>
                    </fieldset>
<?php

                    return true;
                    break;

                case 'backend_import_entry':
                    //TODO: (ph) Maybe handle caching?
                    if (is_array($addData) && !$addData['nl2br']){
                        $props = array();
                        $props['no_nl2br'] = 'true';
                        $this->addProperties($props, $eventData);
                    }
                break;

                case 'backend_entry_presave':
                    if (is_array($serendipity['POST']['properties'])) {
                        $this->applyProperties($serendipity['POST']['properties']);
                    }
                    break;

                case 'backend_publish':
                case 'backend_save':
                    if (!isset($eventData['id'])) {
                        return true;
                    }

                    $serendipity['POST']['properties']['sorting_priority'] = 114;

                    $this->addProperties($serendipity['POST']['properties'], $eventData);

                    return true;
                    break;

                case 'frontend_configure':
                    if (isset($serendipity['POST']['id']) && empty($serendipity['GET']['id'])) {
                        $serendipity['GET']['id']      = &$serendipity['POST']['id'];
                        $serendipity['GET']['subpage'] = &$serendipity['POST']['subpage'];
                    }
                    break;

                case 'frontend_entryproperties':
                    $q = "SELECT entryid, property, value FROM {$serendipity['dbPrefix']}entryproperties WHERE entryid IN (" . implode(', ', array_keys($addData)) . ")";

                    $properties = serendipity_db_query($q);
                    if (!is_array($properties)) {
                        return true;
                    }

                    foreach($properties AS $idx => $row) {
                        $eventData[$addData[$row['entryid']]]['properties'][$row['property']] = $row['value'];
                    }
                    return true;
                    break;

                case 'entry_display':
                    // PH: This is done after Garvins suggestion to patchup $eventData in case an entry
                    //     is in the process of being created. This must be done for the extended properties
                    //     to be applied in the preview.

                    if ($addData['preview'] && is_array($serendipity['POST']['properties']) && count($serendipity['POST']['properties']) > 0){
                        $parr = array();
                        $supported_properties = serendipity_event_entryproperties::getSupportedProperties();
                        foreach($supported_properties AS $prop_key) {
                            if (isset($serendipity['POST']['properties'][$prop_key]))
                                $eventData[0]['properties']['ep_' . $prop_key] = $serendipity['POST']['properties'][$prop_key];
                        }
                    }

                    break;

                case 'frontend_fetchentries':
                case 'frontend_fetchentry':
                    break;

                case 'backend_plugins_new_instance':
                    // This hook will always push the entryproperties plugin as last in queue.
                    // Happens always when a new plugin is added.
                    // This is important because of its caching mechanism!

                    // Fetch maximum sort_order value. This will be the new value of our current plugin.
                    $q  = "SELECT MAX(sort_order) as sort_order_max FROM {$serendipity['dbPrefix']}plugins WHERE placement = '" . $addData['default_placement'] . "'";
                    $rs  = serendipity_db_query($q, true, 'num');

                    // Fetch current sort_order of current plugin.
                    $q   = "SELECT sort_order FROM {$serendipity['dbPrefix']}plugins WHERE name = '" . $this->instance . "'";
                    $cur = serendipity_db_query($q, true, 'num');

                    // Decrease sort_order of all plugins after current plugin by one.
                    $q = "UPDATE {$serendipity['dbPrefix']}plugins SET sort_order = sort_order - 1 WHERE placement = '" . $addData['default_placement'] . "' AND sort_order > " . intval($cur[0]);
                    serendipity_db_query($q);

                    // Set current plugin as last plugin in queue.
                    $q = "UPDATE {$serendipity['dbPrefix']}plugins SET sort_order = " . intval($rs[0]) . " WHERE name = '" . $this->instance . "'";
                    serendipity_db_query($q);

                    return true;
                    break;

                default:
                    return false;
                    break;
            }
        } else {
            return false;
        }
    }
}
4. Now that each entry seems to have a priority value... how can I use that for sorting? I'd like to put the sorting into this plugin as well, but I fear that it would affect the categorytemplate plugin, and I certainly don't want that.

After all, I would love to make the plugin public once it works as intended. I really think it could be very useful, not only for my purpose.

Thanks in advance :)
Jan
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Customizable entry order

Post by garvinhicking »

Hi!

The entryproperties plugin is quite internal, so I actually wouldn't recommend to clone it! Instead, you can just configure the normal entryproperties plugin, add a filed like "ep_sortingorder" to the configuration inside the list of available fields. This will then show up in your blog editing interface.

Now you should basically only need to use that database field name "ep_sortingorder.value", I believe - you'd need the actual name if you look at the serendipity_fetchEntries() function and echo the SQL statement, this is where you see how the entryproperties plugin puts its custom field names into.

There currently is no way to only allow inputting numbers in a box using this method. As for straight PHP, there is a propbag attribute called "validate" where you can put "number" into so that the configuration of a plugin only allows numbers. But this only applies to the plugin configuration screen of a plugin, not to the custom output it generates on the backend. There, you would need your own PHP code to validate input and emit error messages.

You already achieved quite a lot, even though it was in a direction that you might not even have needed. I hope my text makes some sense to you so that you can evaluate a further approach. I'll try to continue helping here of course, if you have more questions and want to share your progress. Sadly I don'T have the time to write up all the small single steps for setting up the aforementioned.

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
TheSHEEEP
Regular
Posts: 16
Joined: Tue Dec 07, 2010 6:44 pm
Location: Berlin

Re: Customizable entry order

Post by TheSHEEEP »

Alright, I think modifying the entryproperties plugin will be a lot easier.

I also noticed that after logging out and in again, the priority value was not saved, it was reset to 0. No idea what I did wrong that caused the value not to be saved, but I hope things will turn out better when I just add stuff to the plugin, as you proposed :)

Once it works, I will put a "manual" here that tells how to do it. Not as cool as a plugin, but nvm ;)
TheSHEEEP
Regular
Posts: 16
Joined: Tue Dec 07, 2010 6:44 pm
Location: Berlin

Re: Customizable entry order

Post by TheSHEEEP »

Okay, I managed to create a working sorting value field into the entryproperties plugin.

But when I try to order by that value, I get the following SQL error:
/ Unknown column 'sorting_priority' in 'order clause'
caused by trying to sort by "sorting_priority DESC".
I also tried with ep.sorting_priority.value, ep.sorting_priority and ep_sorting_priority. All with the same result.

I found this in the code creating the query:

Code: Select all

$conds[] = 'ep_cache_extended.value AS ep_cache_extended,';
                        $conds[] = 'ep_cache_body.value     AS ep_cache_body,';
Then I tried the same with

Code: Select all

"$conds[] = 'ep_sorting_priority.value     AS sorting_priority,';"
but that ended with ep_sorting_priority.value (and all others mentioned above) being unknown in the "field list".


An investigation (phpMyAdmin) turned out that the value "ep_sorting_priority" exists in the entryproperties table. Just as ep_cache_extended does, but in contrast to that value, "including" it via "$conds[] = 'ep_sorting_priority.value AS sorting_priority,';" does not work.
Question: Why does one work while the other one doesn't? Both commands seem completely equal to me.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Customizable entry order

Post by garvinhicking »

Hi!

Yeah, that was what I was talking about that might require you to inspect the actual SQL query that is sent to you rserver. Check the include/functions_entries.inc.php file, serendipity_fetchentries() for the "echo $query" part or so, it should be in there but // commented out. If you remove that, you can see the SQL output when viewing your blog. This will then help you to find out the actual column name.

I cannot look it up right now, the only problem I can think of is that maybe user entered custom property fields are NOT joined as an aliased table (like ep_cache_body) etc., but only in a generic format. In that case you do might need to modify the SQL creation code inside the plugin to also create a "JOIN serendipity_entryproperties AS ep_priority_value ..." like it is with others.

But before you dive into that, try the first thing.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
TheSHEEEP
Regular
Posts: 16
Joined: Tue Dec 07, 2010 6:44 pm
Location: Berlin

Re: Customizable entry order

Post by TheSHEEEP »

Oh, there is nothing commented out in that function that I could put back in.
And I see the failed SQL query. It is the following (probably should have included that before):

Code: Select all

SELECT 
                    ep_sticky.value AS orderkey,
ep_sorting_priority.value AS sorting_priority,

                    e.id,
                    e.title,
                    e.timestamp,
                    e.comments,
                    e.exflag,
                    e.authorid,
                    e.trackbacks,
                    e.isdraft,
                    e.allow_comments,
                    e.last_modified,

                    a.realname AS author,
                    a.username AS loginname,
                    a.email
                     , e.body, e.extended
                     
                FROM
                    s9y_entries AS e
                    LEFT JOIN s9y_authors a
                        ON e.authorid = a.authorid
                    LEFT JOIN s9y_entrycat ec
                        ON e.id = ec.entryid
                    LEFT JOIN s9y_category c
                        ON ec.categoryid = c.categoryid
                     LEFT OUTER JOIN s9y_entryproperties ep_access
                                              ON (e.id = ep_access.entryid AND ep_access.property = 'ep_access')
 LEFT JOIN s9y_entryproperties ep_sticky
                                            ON (e.id = ep_sticky.entryid AND ep_sticky.property = 'ep_is_sticky') LEFT JOIN s9y_authorgroups AS acl_a
                                   ON acl_a.authorid = 1
                            LEFT JOIN s9y_access AS acl_acc
                                   ON (    acl_acc.artifact_mode = 'read'
                                       AND acl_acc.artifact_type = 'category'
                                       AND acl_acc.artifact_id   = c.categoryid
                                      )
                    WHERE isdraft = 'false' AND (( (c.category_left  BETWEEN 4 AND 5))) AND e.timestamp <= 1294755300 AND  (ep_access.property IS NULL OR ep_access.value = 'member' OR ep_access.value = 'public' OR (ep_access.value = 'private' AND e.authorid = 1))   AND     (
                                 c.categoryid IS NULL
                                 OR ( acl_acc.groupid = acl_a.groupid OR acl_acc.groupid = 0)
                                 OR ( acl_acc.artifact_id IS NULL
                                      
                                    )
                               )
                     GROUP BY e.id
                     
                     ORDER BY orderkey DESC, sorting_priority DESC, timestamp DESC/*categorytemplate*/
                      LIMIT 5

/ Unknown column 'ep_sorting_priority.value' in 'field list'
But that doesn't exactly help me to find the correct name. It just tells me that "ep_sorting_priority.value" is not there. But "ep_sorting_priority" actually is there, in the entryproperties table... but somehow that doesn't seem to matter for that query.

I will try the JOIN, then.

Edit:
Oh, well, that was surprisingly easy. I just copy-pasted another JOIN from the plugin and isnerted my variable name. And it worked instantly. Thanks for the help.
I'll now test it further and make a guide on how to achieve that custom sorting.
Last edited by TheSHEEEP on Tue Jan 11, 2011 3:37 pm, edited 1 time in total.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Customizable entry order

Post by garvinhicking »

Hi!

Okay, that's good to know. What basically should work is this little event plugin:

(it is used additionally to your custom prioritysort field, so still depends on entryproperties!)

Code: Select all

<?php
class serendipity_event_prioritysort extends serendipity_event {
  var $title = 'Priority Sort';

  function introspect(&$propbag) {
        global $serendipity;

        $propbag->add('name',          'Priority Sort');
        $propbag->add('version',       '1.0');
        $propbag->add('requirements',  array(
            'serendipity' => '0.8',
            'smarty'      => '2.6.7',
            'php'         => '4.1.0'
        ));
        $propbag->add('event_hooks',    array(
            'frontend_fetchentries'                             => true,
            'frontend_fetchentry'                               => true,
        ));
    }

    function event_hook($event, &$bag, &$eventData, $addData = null) {
        global $serendipity;

        $hooks = &$bag->get('event_hooks');

        if (isset($hooks[$event])) {
            switch($event) {
                case 'frontend_fetchentries':
                case 'frontend_fetchentry':
                    $joins = array();
                    $conds = array();
                    $eventData['joins'] =. " LEFT OUTER JOIN {$serendipity['dbPrefix']}entryproperties AS ep_sorting_priority
                                              ON (e.id = ep_sorting_priority.entryid AND ep_sorting_priority.property = 'ep_sorting_priority')";

                    $eventData['orderby'] = 'ep_sorting_priority.value, ' . $eventData['orderby'];
                    return true;
                    break;

                default:
                    return false;
                    break;
            }
        } else {
            return false;
        }
    }
}

?>

(It's untested, but hopefully works. Save it as serendipity_event_prioritysort/serendipity_event_prioritysort.php and enable it through your plugin manager)

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
TheSHEEEP
Regular
Posts: 16
Joined: Tue Dec 07, 2010 6:44 pm
Location: Berlin

Re: Customizable entry order

Post by TheSHEEEP »

Ah, I've edited my entry while you replied ;)

I've now tested some mixtures and it always seems to work. I'd rather not make an extra plugin. The way it is now, all one needs to do is modifying the entryproperties plugin.
The only "downside" is that it interprets the value as a string and sorts accordingly.

Here is the guide (V1.0):

1. Install the categorytemplate plugin ("Properties/Templates of categories"), it gives each category a field where you can enter your sorting value.

2. Install the entryproperties plugin ("Extended properties for entries"). You will need to edit this.

3. Open the serendipity_event_entryproperties.php, which resides inside plugins/ serendipity_event_entryproperties, with an editor of your choice.

4. Go to the "introspect(&$propbag)" function and change the configuration add to the following:

Code: Select all

$propbag->add('configuration', array('sorting_priority', 'cache', 'sequence', 'use_groups', 'use_users', 'use_ext_joins', 'default_read', 'customfields'));
5. Go to the "introspect_config_item($name, &$propbag)" function below and insert the following case (doesn't matter where):

Code: Select all

case 'sorting_priority':
                $propbag->add('type',        'string');
                $propbag->add('name',        PLUGIN_EVENT_ENTRYPROPERTIES_PRIORITY);
                $propbag->add('description', PLUGIN_EVENT_ENTRYPROPERTIES_PRIORITY_DESC);
                $propbag->add('default',     '0');
                break;
6. Go to the "getSupportedProperties()" function and change the line that sets the supported properties to this one:

Code: Select all

$supported_properties = array('sorting_priority', 'is_sticky', 'access', 'access_groups', 'access_users', 'cache_body', 'cache_extended', 'no_frontpage', 'hiderss', 'entrypassword');
7. Go to the "showBackend($element, etc." function and change the function header by inserting "$sorting_priority" at the 3rd place so that it looks like this:

Code: Select all

function showBackend($element, $eventData, $sorting_priority, $is_sticky, etc.
7.1 In the same function, insert the following case:

Code: Select all

case 'priority':
?>            
            <div class="entryproperties_sorting_priority">
                <input class="input_textbox" type="text" name="serendipity[properties][sorting_priority]" id="properties_sorting_priority" value="<?php echo $sorting_priority?>"/>
                    <label title="<?php echo PLUGIN_EVENT_ENTRYPROPERTIES_PRIORITY; ?>" for="properties_sorting_priority">&nbsp;<?php echo PLUGIN_EVENT_ENTRYPROPERTIES_PRIORITY_DESC; ?>&nbsp;&nbsp;</label>
            </div>
<?php
        break;
8. Go to the "event_hook" function.
Now, go to the "backend_display" case and insert the following piece of code before the fieldset is created:

Code: Select all

if (isset($eventData['properties']['ep_sorting_priority'])) {
                        $sorting_priority = $eventData['properties']['ep_sorting_priority'];
                    } elseif (isset($serendipity['POST']['properties']['sorting_priority'])) {
                        $sorting_priority = $serendipity['POST']['properties']['sorting_priority'];
                    } else {
                        $sorting_priority = $this->get_config('sorting_priority', '0');
                    }
8.1 Replace the foreach loop in the same case with this one (inserted $sorting_priority):

Code: Select all

foreach($elements AS $element) {
                        $this->showBackend($element, $eventData, $sorting_priority, $is_sticky, $no_frontpage, $hiderss, $access_values, $access, $password, $use_groups, $access_groups, $use_users, $access_users, $more);
                    }
8.2 Now, go to the "frontend_fetchentry" case in the function and insert the following line before "$cond = implode("\n", $conds);":

Code: Select all

$conds[] = 'ep_sorting_priority.value AS sorting_priority,';
8.3 In the same case, insert the following LEFT OUTER JOIN where all the other LEFT OUTER JOINS are created. I've inserted it as a first LEFT OUTER JOIN, but I doubt that it matters.

Code: Select all

$joins[] = " LEFT OUTER JOIN {$serendipity['dbPrefix']}entryproperties ep_sorting_priority
                                                  ON (e.id = ep_sorting_priority.entryid AND ep_sorting_priority.property = 'ep_sorting_priority')";
9. Place the following lines in the language file:

Code: Select all

@define('PLUGIN_EVENT_ENTRYPROPERTIES_PRIORITY', 'Sorting priority');
@define('PLUGIN_EVENT_ENTRYPROPERTIES_PRIORITY_DESC', 'This value defines at what place in the entry list this entry is displayed. Needs the "Sort order" in the category to be set to "sorting_priority DESC" or "sorting_priority ASC".');
10. Remember to enable the new priority field in the entryproperties-plugin-configuration.
Also remember to make use of the plugin in the categories, where you want your entries to be custom-sorted. "sorting_priority ASC" will put the lowest priority first.

Important: The query actually interprets the priority_value as a string. That means, if you have the following priorities: 0,300,3,1,400,4, the order will be (if you chose "sorting_priority ASC"): 0,1,3,300,4,400.
Post Reply