/adi_matrix/adi_matrix.php
PHP | 3752 lines | 2817 code | 366 blank | 569 comment | 603 complexity | 0cde546f0fead1d7451d5decc8cffe9c MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- <?php
- // This is a PLUGIN TEMPLATE for Textpattern CMS.
- // Copy this file to a new name like abc_myplugin.php. Edit the code, then
- // run this file at the command line to produce a plugin for distribution:
- // $ php abc_myplugin.php > abc_myplugin-0.1.txt
- // Plugin name is optional. If unset, it will be extracted from the current
- // file name. Plugin names should start with a three letter prefix which is
- // unique and reserved for each plugin author ("abc" is just an example).
- // Uncomment and edit this line to override:
- $plugin['name'] = 'adi_matrix';
- // Allow raw HTML help, as opposed to Textile.
- // 0 = Plugin help is in Textile format, no raw HTML allowed (default).
- // 1 = Plugin help is in raw HTML. Not recommended.
- # $plugin['allow_html_help'] = 1;
- $plugin['version'] = '2.1beta2';
- $plugin['author'] = 'Adi Gilbert';
- $plugin['author_uri'] = 'http://www.greatoceanmedia.com.au/';
- $plugin['description'] = 'Multi-article update tabs';
- // Plugin load order:
- // The default value of 5 would fit most plugins, while for instance comment
- // spam evaluators or URL redirectors would probably want to run earlier
- // (1...4) to prepare the environment for everything else that follows.
- // Values 6...9 should be considered for plugins which would work late.
- // This order is user-overrideable.
- $plugin['order'] = '5';
- // Plugin 'type' defines where the plugin is loaded
- // 0 = public : only on the public side of the website (default)
- // 1 = public+admin : on both the public and admin side
- // 2 = library : only when include_plugin() or require_plugin() is called
- // 3 = admin : only on the admin side (no AJAX)
- // 4 = admin+ajax : only on the admin side (AJAX supported)
- // 5 = public+admin+ajax : on both the public and admin side (AJAX supported)
- $plugin['type'] = '1';
- // Plugin "flags" signal the presence of optional capabilities to the core plugin loader.
- // Use an appropriately OR-ed combination of these flags.
- // The four high-order bits 0xf000 are available for this plugin's private use
- if (!defined('PLUGIN_HAS_PREFS')) define('PLUGIN_HAS_PREFS', 0x0001); // This plugin wants to receive "plugin_prefs.{$plugin['name']}" events
- if (!defined('PLUGIN_LIFECYCLE_NOTIFY')) define('PLUGIN_LIFECYCLE_NOTIFY', 0x0002); // This plugin wants to receive "plugin_lifecycle.{$plugin['name']}" events
- $plugin['flags'] = '3';
- // Plugin 'textpack' is optional. It provides i18n strings to be used in conjunction with gTxt().
- // Syntax:
- // ## arbitrary comment
- // #@event
- // #@language ISO-LANGUAGE-CODE
- // abc_string_name => Localized String
- /** Uncomment me, if you need a textpack
- $plugin['textpack'] = <<<EOT
- #@admin
- #@language en-gb
- abc_sample_string => Sample String
- abc_one_more => One more
- #@language de-de
- abc_sample_string => Beispieltext
- abc_one_more => Noch einer
- EOT;
- **/
- // End of textpack
- if (!defined('txpinterface'))
- @include_once('zem_tpl.php');
- # --- BEGIN PLUGIN CODE ---
- // NOTE
- /*
- adi_matrix - Multi-article update tabs
- Written by Adi Gilbert
- Released under the GNU General Public License
- Version history:
- 2.1 - further updates for TXP 4.6
- - de-colon-isation
- 2.0.1beta - fix: enforce unique IDs on glz_cfs checkbox input fields, so that the <input>/<for> tags match up
- 2.0 - enhancements:
- - publish & delete articles (for mrdale)
- - extra article data options: title, section
- - show sections
- - added section & author to article title tooltip
- - matrix under Content or Home tab
- - improved validation error messages
- - custom WHERE clause conditions
- - article list paging
- - requires TXP 4.5+
- - tested on TXP 4.6
- - fix: matrix privileges
- - improved validation message (URL-only titles)
- - article edit link styling
- - and as Apple says "Includes general performance and stability improvements", as well as code "sanity" improvements for my sake
- 1.2 - TXP 4.5-ified
- - French colon-isation
- - lifecycle "upgrade" pseudo-event
- 1.1 - code tidy up (thanks gocom)
- - enhancement: matrix tab optional footer
- - enhancement: matrix tab column sorting
- - enhancement: "Any parent" & "Any child" category wildcards
- - enhancement: posted timestamp (& reset)
- - enhancement: expires timestamp
- - enhancement: multi-section select (for maniqui & mrdale)
- - enhancement: input field tooltips (for masa)
- - for mrdale:
- - <body class="adi_matrix"> on all matrix tabs
- - another attempt at horizontal scrolling, this time with a fixed article title column
- - more sorting options
- - TinyMCE support for glz_custom_field textareas
- - option to include descendent categories
- - fixed: checkboxes again! (thanks redbot)
- - changed: "Nothing to do" message changed to "No articles modified"
- - changed: admin tab name/title now "Article Matrix"/"Article Matrix Admin"
- 1.0.1 - not officially released
- - fixed: completely unticked checkboxes not updated (thanks redbot)
- - fixed: detect glz_custom_fields in plugin cache (thanks gocom)
- 1.0 - enhancement: glz_custom_fields compatibility
- - enhancement: force numeric sort (for jpdupont)
- - enhancement: sort by Expires timestamp
- - enhancement: article catagories (for maniqui)
- - enhancement: option to switch on horizontal scroll (for mrdale)
- - fixed: MySQL 4.1 compatibility (thanks colak)
- - fixed: error if custom field contains single quote (thanks maniqui)
- - fixed: superfluous "Logged in user" wildcard option in matrix appearance
- - now uses lifecycle events
- 0.3 - enhancement: "One category", "Two categories" wildcards
- - enhancement: timestamp (for CeBe)
- - enhancement: expiry (for CeBe)
- - enhancement: future/expired articles highlighted & preference (for CeBe)
- - enhancement: article title tooltip, & preference
- - admin: install/uninstall/textpack moved to plugin options
- 0.2 - fixed: missing child categories (thanks Zanza)
- - enhancement: "No category", "Any category" wildcards
- - enhancement: "Logged in user" wildcard
- - enhancement: article image field (for Zanza)
- - enhancement: article limit preference (for milosevic)
- 0.1 - initial release
- Custom fields
- - "standard" TXP custom fields: custom_1 ...custom_10, always present
- - with glz_custom_fields, standard CFs can disappear (on "reset"), or additional ones added: custom_11 ...
- Upgrade notes (1.0 - 1.1+)
- - due to bug in 1.0, expires sort option will get changed to modified
- Downgrade (from 2.0 to 1.1/1.2 only)
- - go to adi_matrix plugin options tab
- - add "&step=downgrade" to end of URL & hit return
- - then immediately install previous version of adi_matrix
- - BEWARE: multiple sections won't translate very well
- - adi_matrix_article_limit pref will be reset to 100
- */
- /* TODO
- - fix up proper ui-icon/ui-icon-pencil for edit link
- */
- if (txpinterface === 'admin') {
- global $adi_matrix_debug,$adi_matrix_dump,$adi_matrix_txp460;
- $adi_matrix_debug = 0; // general debuggy info
- $adi_matrix_dump = 0; // dump of article data
- // using article_validate & new default section pref (4.5.0), so decamp sharpish if need be
- if (!version_compare(txp_version,'4.5.0','>=')) return;
- $adi_matrix_txp460 = (version_compare(txp_version,'4.6-dev','>='));
- adi_matrix_init();
- }
- function adi_matrix_init() {
- // general setup
- global $event,$step,$prefs,$txp_groups,$txp_user,$txp_permissions,$theme,$textarray,$adi_matrix_url,$adi_matrix_glz_cfs,$adi_matrix_privs,$adi_matrix_groups,$adi_matrix_cfs,$adi_matrix_expiry_options,$adi_matrix_statuses,$adi_matrix_sort_options,$adi_matrix_sort_dir,$adi_matrix_timestamp_options,$adi_matrix_prefs,$adi_matrix_plugin_status,$adi_matrix_debug,$adi_matrix_glz_cfs,$adi_matrix_list,$adi_matrix_validation_errors,$adi_matrix_sort_type,$adi_matrix_categories,$adi_matrix_tabs,$adi_matrix_txp460;
- $adi_matrix_txp460 = (version_compare(txp_version,'4.6-dev','>='));
- # --- BEGIN PLUGIN TEXTPACK ---
- $adi_matrix_gtxt = array(
- 'adi_alphabetical' => 'Alphabetical',
- 'adi_any_category' => 'Any category',
- 'adi_any_child_category' => 'Any child category',
- 'adi_article_data' => 'Article Data',
- 'adi_article_matrix' => 'Article Matrix',
- 'adi_article_highlighting' => 'Article title highlighting',
- 'adi_article_limit' => 'Maximum number of articles',
- 'adi_articles_not_modified' => 'No articles modified',
- 'adi_article_selection' => 'Article Selection',
- 'adi_article_tooltips' => 'Article title tooltips',
- 'adi_article_update_fail' => 'Article update failed',
- 'adi_articles_saved' => 'Articles saved',
- 'adi_blank_url_title' => 'URL-only title blank',
- 'adi_cancel' => 'Cancel',
- 'adi_custom_condition' => 'Custom condition',
- 'adi_cf_links' => 'Custom field links',
- 'adi_default_sort' => 'Default sort',
- 'adi_display_article_id' => 'Display article ID#',
- 'adi_duplicate_url_title' => 'URL-only title already used',
- 'adi_edit_titles' => 'Edit titles',
- 'adi_expiry' => 'Expiry',
- 'adi_footer' => 'Footer',
- 'adi_has_expiry' => 'Has expiry',
- 'adi_include_descendent_cats' => 'Include descendent categories',
- 'adi_install_fail' => 'Unable to install',
- 'adi_installed' => 'Installed',
- 'adi_invalid_timestamp' => 'Invalid timestamp',
- 'adi_jquery_ui' => 'jQuery UI script file',
- 'adi_jquery_ui_css' => 'jQuery UI CSS file',
- 'adi_logged_in_user' => 'Logged in user',
- 'adi_matrix' => 'Matrix',
- 'adi_matrix_admin' => 'Article Matrix Admin',
- 'adi_matrix_total_articles' => 'Total articles in matrix:',
- 'adi_matrix_cfs_modified' => 'Custom field list modified',
- 'adi_matrix_delete_fail' => 'Matrix delete failed',
- 'adi_matrix_deleted' => 'Matrix deleted',
- 'adi_matrix_input_field_tooltips' => 'Input field tooltips',
- 'adi_matrix_validation_error' => 'Validation errors',
- 'adi_matrix_name' => 'Matrix name',
- 'adi_matrix_update_fail' => 'Matrix settings update failed',
- 'adi_matrix_updated' => 'Matrix settings updated',
- 'adi_new_article' => 'New article',
- 'adi_no_category' => 'No category',
- 'adi_no_expiry' => 'No expiry',
- 'adi_not_installed' => 'Not installed',
- 'adi_numerical' => 'Numerical',
- 'adi_ok' => 'OK',
- 'adi_one_category' => 'One category',
- 'adi_any_parent_category' => 'Any parent category',
- 'adi_pref_update_fail' => 'Preference update failed',
- 'adi_reset' => 'Reset',
- 'adi_scroll' => 'Scroll',
- 'adi_show_section' => 'Show section',
- 'adi_sort_type' => 'Sort type',
- 'adi_tab' => 'Tab',
- 'adi_textpack_fail' => 'Textpack installation failed',
- 'adi_textpack_feedback' => 'Textpack feedback',
- 'adi_textpack_online' => 'Textpack also available online',
- 'adi_tiny_mce' => 'TinyMCE',
- 'adi_tiny_mce_dir_path' => 'TinyMCE directory path',
- 'adi_tiny_mce_hak' => 'TinyMCE (hak_tinymce)',
- 'adi_tiny_mce_javascript' =>'TinyMCE (Javascript)',
- 'adi_tiny_mce_jquery' => 'TinyMCE (jQuery)',
- 'adi_tiny_mce_config' => 'TinyMCE configuration',
- 'adi_two_categories' => 'Two categories',
- 'adi_uninstall' => 'Uninstall',
- 'adi_uninstall_fail' => 'Unable to uninstall',
- 'adi_uninstalled' => 'Uninstalled',
- 'adi_update_matrix' => 'Update matrix settings',
- 'adi_update_prefs' => 'Update preferences',
- 'adi_upgrade_fail' => 'Unable to upgrade',
- 'adi_upgrade_required' => 'Upgrade required',
- 'adi_upgraded' => 'Upgraded',
- 'adi_user' => 'User',
- );
- # --- END PLUGIN TEXTPACK ---
- // update $textarray
- $textarray += $adi_matrix_gtxt;
- // Textpack
- $adi_matrix_url = array(
- 'textpack' => 'http://www.greatoceanmedia.com.au/files/adi_textpack.txt',
- 'textpack_download' => 'http://www.greatoceanmedia.com.au/textpack/download',
- 'textpack_feedback' => 'http://www.greatoceanmedia.com.au/textpack/?plugin=adi_matrix',
- );
- if (strpos($prefs['plugin_cache_dir'],'adi') !== FALSE) // use Adi's local version
- $adi_matrix_url['textpack'] = $prefs['plugin_cache_dir'].'/adi_textpack.txt';
- // plugin lifecycle
- register_callback('adi_matrix_lifecycle','plugin_lifecycle.adi_matrix');
- // adi_matrix admin tab
- add_privs('adi_matrix_admin'); // add priv group - defaults to priv '1' only
- register_tab('extensions','adi_matrix_admin',gTxt('adi_article_matrix')); // add new tab under 'Extensions'
- register_callback('adi_matrix_admin','adi_matrix_admin');
- // look for glz_custom_fields
- $adi_matrix_glz_cfs = load_plugin('glz_custom_fields');
- /* User privilege summary:
- 0 - none - can't even login
- 1 - publisher - full matrix data & adi_matrix admin capability
- 2 - manager - matrix data only
- 3 - copy editor - matrix data only
- 4 - staff writer - matrix data only
- 5 - freelancer - matrix data only
- 6 - designer - matrix data only
- Standard article editing privileges:
- 'article.edit' => '1,2,3',
- 'article.edit.published' => '1,2,3',
- 'article.edit.own' => '1,2,3,4,5,6',
- 'article.edit.own.published' => '1,2,3,4',
- */
- // defines privileges required to view a matrix with privilege restriction (same indexing as $txp_groups)
- $adi_matrix_privs = array(
- 1 => '1', // publisher
- 2 => '1,2', // managing_editor
- 3 => '1,2,3', // copy_editor
- 4 => '1,2,3,4', // staff_writer
- 5 => '1,2,3,4,5', // freelancer
- 6 => '1,6', // designer
- );
- // set up user privilege names
- $adi_matrix_groups = $txp_groups; // to get: 1 => 'publisher', 2 => 'managing_editor' etc
- unset($adi_matrix_groups[0]); // lose index zero (none) - gets us a blank select option too!
- foreach ($adi_matrix_groups as $index => $group)
- $adi_matrix_groups[$index] = gTxt($group); // to get: 1 => 'Publisher', 2 => 'Managing Editor' etc in the language 'de jour'
- // discover custom fields (standard 1-10 & glz 11+) and their non-lowercased titles
- $adi_matrix_cfs = getCustomFields();
- foreach ($adi_matrix_cfs as $index => $value)
- $adi_matrix_cfs[$index] = $prefs['custom_'.$index.'_set']; // index = custom fields number, value = custom field title
- // build a picture of article categories
- $adi_matrix_categories = adi_matrix_categories(getTree('root','article'));
- // article expiry options
- $adi_matrix_expiry_options = array(
- 0 => '',
- 1 => gTxt('adi_no_expiry'),
- 2 => gTxt('adi_has_expiry'),
- 3 => gTxt('expired'),
- );
- // article status code translation
- $adi_matrix_statuses = array(
- 1 => gTxt('draft'),
- 2 => gTxt('hidden'),
- 3 => gTxt('pending'),
- 4 => gTxt('live'),
- 5 => gTxt('sticky'),
- );
- // article sort options
- $adi_matrix_sort_options = array(
- 'posted' => gTxt('posted'),
- 'title' => gTxt('title'),
- 'id' => gTxt('id'),
- 'lastmod' => gTxt('article_modified'),
- 'expires' => gTxt('expires'),
- 'status' => gTxt('status'),
- 'keywords' => gTxt('keywords'),
- 'article_image' => gTxt('article_image'),
- 'category1' => gTxt('category1'),
- 'category2' => gTxt('category2'),
- 'section' => gTxt('section'),
- );
- foreach ($adi_matrix_cfs as $index => $value) // add custom fields to sort options
- $adi_matrix_sort_options['custom_'.$index] = $adi_matrix_cfs[$index];
- // article sort direction
- $adi_matrix_sort_dir = array(
- 'desc' => gTxt('descending'),
- 'asc' => gTxt('ascending'),
- );
- // article sort type
- $adi_matrix_sort_type = array(
- 'alphabetical' => gTxt('adi_alphabetical'),
- 'numerical' => gTxt('adi_numerical'),
- );
- // article timestamp options
- $adi_matrix_timestamp_options = array(
- 'any' => gTxt('time_any'),
- 'past' => gTxt('time_past'),
- 'future' => gTxt('time_future'),
- );
- // validation errors
- $adi_matrix_validation_errors = array(
- 0 => gTxt('adi_invalid_timestamp'),
- 1 => gTxt('article_expires_before_postdate'),
- 2 => gTxt('adi_duplicate_url_title'),
- 3 => gTxt('adi_blank_url_title'),
- );
- // default preferences
- $adi_matrix_prefs = array(
- 'adi_matrix_article_highlighting' => array('value' => '1', 'input' => 'yesnoradio'),
- 'adi_matrix_article_tooltips' => array('value' => '1', 'input' => 'yesnoradio'),
- 'adi_matrix_display_id' => array('value' => '0', 'input' => 'yesnoradio'),
- 'adi_matrix_input_field_tooltips' => array('value' => '0', 'input' => 'yesnoradio'),
- 'adi_matrix_jquery_ui' => array('value' => '../scripts/jquery-ui.js', 'input' => 'text_input'),
- 'adi_matrix_jquery_ui_css' => array('value' => '../scripts/jquery-ui.css', 'input' => 'text_input'),
- 'adi_matrix_tiny_mce' => array('value' => '0', 'input' => 'yesnoradio'),
- 'adi_matrix_tiny_mce_type' => array('value' => 'custom', 'input' => 'text_input'),
- 'adi_matrix_tiny_mce_dir' => array('value' => '../scripts/tiny_mce', 'input' => 'text_input'),
- 'adi_matrix_tiny_mce_config' => array('value' => 'see below', 'input' => 'text_area'),
- );
- $adi_matrix_prefs['adi_matrix_tiny_mce_config']['value'] = '
- language : "en",
- theme : "advanced",
- plugins : "safari,pagebreak,style,layer,table,save,advhr,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
- theme_advanced_buttons1 : "pagebreak,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
- theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
- theme_advanced_buttons3 : "tablecontrols",
- theme_advanced_toolbar_location : "top",
- theme_advanced_toolbar_align : "left",
- theme_advanced_statusbar_location : "bottom",
- theme_advanced_resizing : true,
- extended_valid_elements: "style[*]",
- width: "600",
- height: "400",
- ';
- // tabs
- $adi_matrix_tabs = array(
- 'content' => gTxt('tab_content'),
- 'start' => gTxt('tab_start'),
- );
- // plugin options
- $adi_matrix_plugin_status = fetch('status','txp_plugin','name','adi_matrix',$adi_matrix_debug);
- if ($adi_matrix_plugin_status) { // proper install - options under Plugins tab
- add_privs('plugin_prefs.adi_matrix'); // add priv set - defaults to priv '1' only
- register_callback('adi_matrix_options','plugin_prefs.adi_matrix');
- }
- else { // txpdev - options under Extensions tab
- add_privs('adi_matrix_options'); // add priv set - defaults to priv '1' only
- register_tab('extensions','adi_matrix_options','adi_matrix options');
- register_callback('adi_matrix_options','adi_matrix_options');
- }
- // glz_custom_fields stuff
- if ($adi_matrix_glz_cfs) {
- if (strstr($event, 'adi_matrix_matrix_')) {
- // date & time pickers
- add_privs('glz_custom_fields_css_js',"1,2,3,4,5,6");
- register_callback('glz_custom_fields_css_js','admin_side','head_end');
- // TinyMCE
- if (adi_matrix_pref('adi_matrix_tiny_mce')) {
- register_callback('adi_matrix_tiny_mce_style','admin_side','head_end');
- register_callback('adi_matrix_tiny_mce_'.adi_matrix_pref('adi_matrix_tiny_mce_type'),'admin_side','footer');
- }
- }
- }
- // article matrix tabs
- $adi_matrix_list = array();
- if (adi_matrix_installed())
- $adi_matrix_list = adi_matrix_read_settings(adi_matrix_upgrade());
- $all_privs = '1,2,3,4,5,6'; // everybody
- foreach ($adi_matrix_list as $index => $matrix) {
- $matrix_event = 'adi_matrix_matrix_'.$index;
- $matrix_tab_name = $matrix['name'];
- if ($matrix['privs'])
- $priv_set = $adi_matrix_privs[$matrix['privs']];
- else
- $priv_set = $all_privs; // everybody's welcome
- add_privs($matrix_event,$priv_set); // add priv set for each matrix event (to $txp_permissions)
- if ($matrix['user'])
- $user_allowed = ($txp_user == $matrix['user']);
- else // open to all users
- $user_allowed = TRUE;
- $has_privs = has_privs($matrix_event);
- $register_this_tab = ($user_allowed && $has_privs) || has_privs('adi_matrix_admin');
- if ($register_this_tab) {
- $tab = $matrix['tab'];
- if ($tab == 'start') // switch on Home tab
- add_privs('tab.start',$all_privs); // all privs
- register_tab($tab,$matrix_event,$matrix_tab_name);
- register_callback("adi_matrix_matrix",$matrix_event);
- }
- if ($adi_matrix_debug) {
- echo "MATRIX: index=$index, name=".$matrix['name'].", user=".$matrix['user'].", privs=".$matrix['privs'].", priv_set=$matrix_event($priv_set), tab=".$matrix['tab'].br;
- $user_privs = safe_field('privs','txp_users',"name='$txp_user'");
- echo "USER: user=$txp_user, user_privs=$user_privs, user_allowed=$user_allowed, has_privs=$has_privs".br;
- echo "TAB: register_this_tab=$register_this_tab".br.br;
- }
- }
- if ($adi_matrix_debug) {
- echo '<b>$adi_matrix_privs:</b>';
- dmp($adi_matrix_privs);
- echo '<b>adi_matrix added priv sets ($txp_permissions):</b>'.br;
- foreach ($txp_permissions as $index => $value)
- if (strpos($index,'adi_matrix') === 0)
- echo $index.' = '.$value.br;
- }
- // style
- if (strstr($event,'adi_matrix_matrix_') || ($event == 'adi_matrix_admin'))
- register_callback('adi_matrix_style','admin_side','head_end');
- // script
- if (strstr($event,'adi_matrix_admin'))
- register_callback('adi_matrix_admin_script','admin_side','head_end');
- if (strstr($event,'adi_matrix_matrix_'))
- register_callback('adi_matrix_matrix_script','admin_side','head_end');
- }
- function adi_matrix_style() {
- // some style (Classic: table#list, Remora/Hive: table.txp-list)
- global $prefs,$adi_matrix_txp460;
- echo '<style type="text/css">
- /* adi_matrix */
- /* general */
- .txp-body { max-width:none }
- table#list td { padding:0.5em }
- .adi_matrix_button { margin:1em auto; text-align:center }
- .txp-list { width:auto; margin:0 auto }
- /* admin tab */
- .adi_matrix_admin input.radio { margin-left:0.5em }
- .adi_matrix_admin form { text-align:center }
- .adi_matrix_admin table#list td { padding:0.5em 0.5em 0 }
- .adi_matrix_field { text-align:left }
- .adi_matrix_field label { display:block; float:left; width:8em }
- .adi_matrix_field label.adi_matrix_label2 { width:auto }
- .adi_matrix_field p { overflow:hidden; margin-top:0; min-height:1.4em }
- .adi_matrix_field p > span { float:left; width:8em } /* pseudo label */
- .adi_matrix_field p > span + label, .adi_matrix_field p > span + label + label { width:auto } /* radio labels */
- .adi_matrix_field p label.adi_matrix_checkbox { width:auto }
- .adi_matrix_field p label.adi_matrix_checkbox input { float:left; margin-top:0.2em }
- .adi_matrix_field p label.adi_matrix_checkbox span { display:block; float:left; width:8em }
- .adi_matrix_custom_field label { width:12em }
- .adi_matrix_multi_checkboxes { margin:0.3em 0 0.5em; height:5em; padding:0.2em; overflow:auto; border:1px solid #ccc }
- .adi_matrix_multi_checkboxes label { float:none; width:auto }
- .adi_matrix_prefs { margin-top:5em; text-align:center }
- .adi_matrix_prefs input.checkbox { margin-left:0.5em }
- .adi_matrix_prefs input.smallerbox { margin-left:0 }
- .adi_matrix_prefs .adi_matrix_radio label { margin-right:1em }
- .adi_matrix_prefs .adi_matrix_radio input { margin-left:0.5em }
- .adi_matrix_admin .adi_matrix_delete a { font-size:120% }
- /* matrix tabs */
- .adi_matrix_matrix h1 { margin-top:0; text-align:center; font-weight:bold }
- .adi_matrix_matrix table#list th.adi_matrix_noborder { border:0 }
- .adi_matrix_matrix table#list .adi_matrix_delete { font-weight:normal; text-align:center }
- .adi_matrix_matrix table#list .adi_matrix_delete a { font-size:120% }
- .adi_matrix_matrix table#list td.adi_matrix_add { font-size:120% }
- .adi_matrix_matrix .date input { margin-top:0 }
- .adi_matrix_none { margin-top:2em; text-align:center }
- .adi_matrix_field_title { white-space:nowrap } /* stops edit link dropping below */
- .adi_matrix_timestamp { white-space:nowrap } /* stops date or time being split */
- .adi_matrix_future a { font-weight:bold }
- .adi_matrix_expired a { font-style:italic }
- .adi_matrix_error input { border-color:#b22222; color:#b22222 }
- .adi_matrix_matrix .adi_matrix_matrix_prefs { margin-top:4em; text-align:center }
- .adi_matrix_grand_total { text-align:center }
- .adi_matrix_edit_link a { display:inline-block; width:21px; height:21px; line-height:2; border:1px solid #ccc; border-radius:0.4em; background:url(theme/classic/view-text.png) 50% 50% no-repeat #FFF8DD }
- .adi_matrix_edit_link a:hover, .adi_matrix_edit_link a:active { text-decoration:none; background-color:#fff }
- /* matrix tabs 4.5 */
- .txp-list .adi_matrix_timestamp .time input { margin-top:0.5em }
- .txp-list .adi_matrix_timestamp { min-width:11em }
- /* matrix tabs 4.6 */
- .txp-list th,.txp-list td { padding-left:0.5em }
- /* glz_custom_fields */
- html[xmlns] td.glz_custom_date-picker_field.clearfix { display:table-cell!important } /* override clearfix - for date-picker field */
- /*.adi_matrix_matrix input.date-picker { float:left; width:7em }*/
- .adi_matrix_matrix input.date-picker { width:7em } /* 2.0 layout tweak */
- .adi_matrix_matrix td.glz_custom_date-picker_field a.dp-choose-date { display:block; clear:left } /* 2.0 layout tweak */
- /*.adi_matrix_matrix td.glz_custom_date-picker_field { min-width:10em }*/ /* 2.0 layout tweak */
- .adi_matrix_matrix input.time-picker { width:4em }
- /* tinyMCE */
- .adi_matrix_matrix .glz_text_area_field div.tie_div { overflow-y:scroll; width:17.6em; height:5.6em; padding:0.2em; border:1px solid; border-color:#aaa #eee #eee #aaa; background-color: #eee }
- /* scrolling matrix */
- .adi_matrix_scroll table#list th:first-child,
- .adi_matrix_scroll table#list td:first-child { position:absolute; width:13%; left:0; top:auto; padding-right:1em; border-bottom-width:0 }
- .adi_matrix_scroll table#list thead th:first-child { border-bottom-width:1px }
- .adi_matrix_scroll div.scroll_box { width:87%; margin-left:13%; padding-bottom:1em;overflow-x:scroll; overflow-y:visible; border:solid #eee; border-width:0 1px }
- .adi_matrix_scroll table#list tfoot td:first-child { border-top:1px solid #ddd }
- .adi_matrix_scroll table#list tfoot td { border-bottom:0 }
- .adi_matrix_scroll table#list tfoot td:first-child a { display:inline }
- /* footer */
- table#list tfoot td { font-weight:bold }
- table#list tfoot td.desc a,
- table#list tfoot td.asc a { width:auto; background-color:transparent; background-image:url("./txp_img/arrowupdn.gif"); background-repeat: no-repeat; background-attachment: scroll; background-position: right -18px; padding-right: 14px; margin-right: 0pt }
- table#list tfoot td.asc a { background-position: right 2px }
- ';
- if ($prefs['theme_name'] == 'hive')
- echo '
- /* Hive theme (mostly stolen from Hive textpattern.css) */
- .txp-list tfoot td.desc a, table#list tfoot td.asc a { background-image:none }
- .txp-list tfoot td { text-shadow:1px 1px 0 rgba(255, 255, 255, 0.4); background-color:#eee; background-image:linear-gradient(#eee, #ddd); border-top:1px solid #ddd; border-right:1px solid #d0d0d0; border-bottom:1px solid #c4c4c4 }
- .txp-list tfoot td:first-child { border-left:1px solid #ddd }
- .txp-list tfoot td a { position:relative; display:block; color:#333; margin-right:.5em }
- .txp-list tfoot td a:hover { color:#333; text-decoration:none }
- .txp-list tfoot td a:after { position:absolute; top:.53846153846154em; right:-0.76923em; z-index:10; width:0; height:0; display:inline-block; *display:inline; *zoom:1; vertical-align:top; opacity:.5; text-indent:110%; white-space:nowrap; overflow:hidden }
- .txp-list tfoot td a:hover:after { opacity:1 }
- .txp-list tfoot td.desc a:after { content:"↓"; border-left:.30769230769231em solid transparent; border-right:.30769230769231em solid transparent; border-top:0.30769em solid #333; border-bottom:0 }
- .txp-list tfoot td.asc a:after { content:"↑"; border-left:.30769230769231em solid transparent; border-right:.30769230769231em solid transparent; border-top:0; border-bottom:0.30769em solid #333 }
- p.prev-next, form.pageby { text-align:center }
- .adi_matrix_edit_link a { border:1px solid #eee; border-radius:0.5em; background:url(theme/classic/view-text.png) 50% 50% no-repeat #eee }
- .adi_matrix_edit_link a:hover, .adi_matrix_edit_link a:active { background-color:#FFF6D3 }
- ';
- if ($adi_matrix_txp460) {
- echo '
- /* TXP 4.6 only */
- .adi_matrix_edit_link a { width:1.6em; height:1.8em; background-image:url(admin-themes/hive/assets/img/ui-icon-sprite-333333.svg); background-size:320px 340px; background-position: -78px -140px; background-repeat: no-repeat; background-color:transparent; border:0 }
- .adi_matrix_edit_link a:hover, .adi_matrix_edit_link a:active { background-color:transparent }
- .adi_matrix_view_link span + span { display:none }
- ';
- // if ($prefs['theme_name'] == 'hive')
- // echo '
- // /* TXP 4.6 Hive only */
- // .adi_matrix_edit_link a { border:0; border-radius:0.5em }
- // .adi_matrix_edit_link a:hover, .adi_matrix_edit_link a:active { background-color:#FFF6D3 }
- // ';
- }
- echo '</style>'.n;
- }
- /*
- .ui-icon {
- display: inline-block;
- position: relative;
- width: 16px;
- height: 16px;
- background-image: url("../img/ui-icon-sprite-333333.svg");
- background-repeat: no-repeat;
- background-size: 256px 272px;
- text-indent: -9999px;
- overflow: hidden;
- vertical-align: text-bottom;
- }
- background-position: -64px -112px;
- */
- function adi_matrix_admin_script() {
- // jQuery magic for admin tab
- echo <<<END_SCRIPT
- <script type="text/javascript">
- $(function(){
- $("#peekaboo").hide();
- $('input[name="adi_matrix_tiny_mce"][value="1"]:checked').each(function(){
- $("#peekaboo").show();
- });
- $('input[name="adi_matrix_tiny_mce"]:radio:eq(0)').change(function(){
- $("#peekaboo").show();
- });
- $('input[name="adi_matrix_tiny_mce"]:radio:eq(1)').change(function(){
- $("#peekaboo").hide();
- });
- });
- </script>
- END_SCRIPT;
- }
- function adi_matrix_matrix_script() {
- // jQuery action
- // add class to <body>
- echo <<<END_SCRIPT
- <script type="text/javascript">
- $(function(){
- $('body').addClass('adi_matrix');
- // enforce unique ids on glz checkboxes
- $('table.adi_matrix_matrix td.glz_custom_checkbox_field input.checkbox').each(function() {
- var name = $(this).attr('name'); // get value of name (contains article id)
- var new_name = name.replace('article_','');
- var matches = new_name.match(/^[0-9,new]*/); // extract article id#
- var new_id = this.id + '_' + matches[0]; // use article id# as suffix for tag id
- $(this).attr('id',new_id); // set id on input tag
- var td = $(this).parent();
- $('label',td).attr('for',new_id); // set id on label tag
- // console.log(name,new_name,res[0],td);
- });
- });
- </script>
- END_SCRIPT;
- }
- function adi_matrix_read_settings($just_the_basics=FALSE) {
- // get matrix settings from database
- global $adi_matrix_cfs,$adi_matrix_debug;
- $rs = safe_rows_start('*','adi_matrix',"1=1");
- $matrix_list = array();
- if ($rs)
- while ($a = nextRow($rs)) {
- extract($a);
- // just enough to display matrix tab
- $matrix_list[$id]['name'] = $name;
- $matrix_list[$id]['user'] = $user;
- $matrix_list[$id]['privs'] = $privs;
- if (!isset($tab)) // tab introduced in v2.0, so may not be present during upgrade install
- $tab = 'content';
- $matrix_list[$id]['tab'] = $tab;
- // load in the rest
- if (!$just_the_basics) {
- $the_rest = array('sort','dir','sort_type','scroll','footer','title','publish','show_section','cf_links','criteria_section','criteria_category','criteria_descendent_cats','criteria_status','criteria_author','criteria_keywords','criteria_timestamp','criteria_expiry','criteria_condition','status','keywords','article_image','category1','category2','posted','expires','section');
- foreach ($the_rest as $item)
- $matrix_list[$id][$item] = $$item;
- // custom fields
- foreach ($adi_matrix_cfs as $index => $value) {
- $custom_x = 'custom_'.$index;
- if (isset($$custom_x)) // check that custom field is known to adi_matrix
- $matrix_list[$id][$custom_x] = $$custom_x;
- }
- }
- }
- return $matrix_list;
- }
- function adi_matrix_where($criteria=array()) {
- // take matrix criteria & create a WHERE clause
- // mostly ripped off from doArticles() in publish.php
- global $adi_matrix_debug,$adi_matrix_categories;
- if ($adi_matrix_debug) {
- echo "<b>Criteria:</b>";
- dmp($criteria);
- }
- extract($criteria);
- $excerpted = '';
- $month = '';
- $time = $timestamp;
- // categories
- $cats = array();
- if ($category == '!no_category!')
- $category = " and (Category1 = '' and Category2 = '')";
- else if ($category == '!any_category!')
- $category = " and (Category1 != '' or Category2 != '')";
- else if ($category == '!one_category!')
- $category = " and (Category1 != '' and Category2 = '') or (Category1 = '' and Category2 != '')";
- else if ($category == '!two_categories!')
- $category = " and (Category1 != '' and Category2 != '')";
- else if ($category == '!any_parent_category!') {
- foreach ($adi_matrix_categories as $name => $this_cat)
- if ($this_cat['children'])
- $cats[] = $name;
- $category = implode(',',$cats);
- $category = implode("','", doSlash(do_list($category)));
- $category = (!$category) ? '' : " and (Category1 IN ('".$category."') or Category2 IN ('".$category."'))";
- }
- else if ($category == '!any_child_category!') {
- foreach ($adi_matrix_categories as $name => $this_cat)
- if ($this_cat['parent'] != 'root')
- $cats[] = $name;
- $category = implode(',',$cats);
- $category = implode("','", doSlash(do_list($category)));
- $category = (!$category) ? '' : " and (Category1 IN ('".$category."') or Category2 IN ('".$category."'))";
- }
- else { // single category (perhaps with optional descendents)
- if ($descendent_cats)
- $category .= ','.implode(',',$adi_matrix_categories[$category]['children']);
- $category = implode("','", doSlash(do_list($category)));
- $category = (!$category) ? '' : " and (Category1 IN ('".$category."') or Category2 IN ('".$category."'))";
- }
- $section = (!$section) ? '' : " and Section IN ('".implode("','", doSlash(do_list($section)))."')";
- $excerpted = ($excerpted=='y') ? " and Excerpt !=''" : '';
- if ($author == '!logged_in_user!')
- $author = $txp_user;
- $author = (!$author) ? '' : " and AuthorID IN ('".implode("','", doSlash(do_list($author)))."')";
- $month = (!$month) ? '' : " and Posted like '".doSlash($month)."%'";
- // posted timestamp
- switch ($time) {
- case 'any':
- $time = "";
- break;
- case 'future':
- $time = " and Posted > now()";
- break;
- default:
- $time = " and Posted <= now()";
- }
- // expiry
- switch ($expiry) {
- case '1': // no expiry set
- $time .= " and Expires = ".NULLDATETIME;
- break;
- case '2': // has expiry set
- $time .= " and Expires != ".NULLDATETIME;
- break;
- case '3': // expired
- $time .= " and now() > Expires and Expires != ".NULLDATETIME;
- break;
- }
- $custom = ''; // MAY GET CONFUSING WITH criteria_condition
- // if ($customFields) {
- // foreach($customFields as $cField) {
- // if (isset($atts[$cField]))
- // $customPairs[$cField] = $atts[$cField];
- // }
- // if(!empty($customPairs)) {
- // $custom = buildCustomSql($customFields,$customPairs);
- // }
- // }
- if ($keywords) {
- $keys = doSlash(do_list($keywords));
- foreach ($keys as $key) {
- $keyparts[] = "FIND_IN_SET('".$key."',Keywords)";
- }
- $keywords = " and (" . implode(' or ',$keyparts) . ")";
- }
- if ($status)
- $statusq = ' and Status = '.intval($status);
- else // either blank or zero
- $statusq = ''; // all statuses
- if ($condition)
- $conditionq = ' and '.$condition;
- else
- $conditionq = '';
- $where = '1'.$statusq.$time.$category.$section.$excerpted.$month.$author.$keywords.$custom.$conditionq;
- if ($adi_matrix_debug) {
- echo "<b>WHERE clause:</b> $where".br;
- }
- return $where;
- }
- function adi_matrix_order_by($sort,$dir,$sort_type) {
- // generate ORDER BY clause
- // mostly ripped off from doArticles() in publish.php
- global $adi_matrix_debug;
- // map columns to sort query
- switch ($sort) {
- case 'posted':
- $sortq = 'Posted';
- break;
- case 'expires':
- $sortq = 'Expires';
- break;
- case 'lastmod':
- $sortq = 'LastMod';
- break;
- case 'title':
- $sortq = 'Title';
- break;
- case 'id':
- $sortq = 'ID';
- break;
- case 'status':
- $sortq = 'Status';
- break;
- case 'article_image':
- $sortq = 'Image';
- break;
- case 'category1':
- $sortq = 'Category1';
- break;
- case 'category2':
- $sortq = 'Category2';
- break;
- case 'section':
- $sortq = 'Section';
- break;
- default: // custom_x will fall through to here
- $rs = safe_query('SHOW FIELDS FROM '.safe_pfx('textpattern')." LIKE '$sort'",$adi_matrix_debug); // find out if column (glz custom field probably) still exists
- $a = nextRow($rs);
- if (empty($a))
- $sortq = 'Posted';
- else
- $sortq = $sort;
- }
- // sort type
- if ($sort_type == 'numerical')
- $sort_typeq = ' + 0';
- else
- $sort_typeq = '';
- // sort it all out
- $sortq = ' ORDER BY '.$sortq.$sort_typeq.' '.$dir.', Posted desc'; // add direction ... & also secondary sort (pointless but harmless with ID, Posted & Expires)
- if ($adi_matrix_debug) {
- echo "<b>Sort:</b> sort=$sort, dir=$dir, sort_type=$sort_type".br;
- echo "<b>ORDER BY clause:</b> $sortq".br;
- }
- return $sortq;
- }
- function adi_matrix_get_articles($where='1',$sortq='',$matrix_index,$offset,$limit) {
- // read required articles from database and populate $adi_matrix_articles
- global $adi_matrix_debug,$adi_matrix_cfs,$adi_matrix_list,$adi_matrix_sort_options,$txp_user,$adi_matrix_timestamp_options;
- $adi_matrix_articles = array();
- // get the required articles from database
- $rs = safe_rows_start(
- "*, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod"
- ,'textpattern'
- ,$where.doSlash($sortq).' LIMIT '.intval($offset).', '.intval($limit)
- ,$adi_matrix_debug
- );
- if ($rs) // populate $adi_matrix_articles array
- while ($a = nextRow($rs)) {
- extract($a);
- $adi_matrix_articles[$ID] = array();
- $adi_matrix_articles[$ID]['title'] = html_entity_decode($Title, ENT_QUOTES, 'UTF-8');
- $adi_matrix_articles[$ID]['section'] = $Section;
- $adi_matrix_articles[$ID]['author'] = $AuthorID; // need author for article edit priv check
- $adi_matrix_articles[$ID]['status'] = $Status; // need status for article edit priv check
- $adi_matrix_articles[$ID]['keywords'] = $Keywords;
- $adi_matrix_articles[$ID]['article_image'] = $Image;
- $adi_matrix_articles[$ID]['category1'] = $Category1;
- $adi_matrix_articles[$ID]['category2'] = $Category2;
- foreach ($adi_matrix_cfs as $index => $cf_name) {
- $custom_x = 'custom_'.$index;
- $adi_matrix_articles[$ID][$custom_x] = $$custom_x;
- }
- // article timestamps
- $adi_matrix_articles[$ID]['uposted'] = $uPosted; // unix timestamp format (in server timezone)
- $adi_matrix_articles[$ID]['posted'] = $Posted; // article date/time string (YY-MM-DD HH:MM:SS) from database
- $adi_matrix_articles[$ID]['display_posted'] = safe_strftime('%Y-%m-%d %X',$uPosted); // article date/time string (YY-MM-DD HH:MM:SS) displayed to user (TXP time)
- $adi_matrix_articles[$ID]['uexpires'] = $uExpires; // unix timestamp format (in server timezone)
- $adi_matrix_articles[$ID]['expires'] = $Expires; // article date/time string (YY-MM-DD HH:MM:SS) from database
- if ($Expires == '0000-00-00 00:00:00')
- $adi_matrix_articles[$ID]['display_expires'] = $Expires; // keep it zeroed
- else
- $adi_matrix_articles[$ID]['display_expires'] = safe_strftime('%Y-%m-%d %X',$uExpires); // article date/time string (YY-MM-DD HH:MM:SS) displayed to user (TXP time)
- // highlighting
- $highlight = 0;
- $now = time();
- if (($now > $uExpires) && ($uExpires != 0)) // expired article
- $highlight = 1;
- if ($now < $uPosted) // future article
- $highlight = 2;
- $adi_matrix_articles[$ID]['highlight'] = $highlight;
- }
- return $adi_matrix_articles;
- }
- function adi_matrix_update_article($id,$data) {
- // translate $_POSTED article data into SQL-speak
- global $adi_matrix_debug,$txp_user,$adi_matrix_cfs,$adi_matrix_articles,$vars,$prefs;
- include_once txpath.'/include/txp_article.php'; // to get textile_main_fields()
- // set up variables in the style of $vars
- $Title = $Title_plain = isset($data['title']) ? $data['title'] : '';
- $Status = isset($data['status']) ? $data['status'] : '';
- $Section = isset($data['section']) ? $data['section'] : '';
- $Keywords = isset($data['keywords']) ? trim(preg_replace('/( ?[\r\n\t,])+ ?/s', ',', preg_replace('/ +/', ' ', $data['keywords'])), ', ') : '';
- $Image = isset($data['article_image']) ? $data['article_image'] : '';
- $Category1 = isset($data['category1']) ? $data['category1'] : '';
- $Category2 = isset($data['category2']) ? $data['category2'] : '';
- // posted
- if (isset($data['posted']['reset_time']))
- $publish_now = '1';
- else
- $publish_now = '';
- if (isset($data['posted'])) { // this is in TXP date/time
- extract($data['posted']);
- $Posted = $year.'-'.$month.'-'.$day.' '.$hour.':'.$minute.':'.$second;
- }
- else // force now
- $publish_now = '1'; // NOT SURE WHY DOING THIS, BUT DOESN'T DO ANY HARM (IS IGNORED IF POSTED NOT CHANGED)
- // expires
- if (isset($data['expires'])) { // this is in TXP date/time
- foreach ($data['expires'] as $index => $value) { // convert expiry vars ($year -> $exp_year) to align with $vars in txp_article.php
- $var = 'exp_'.$index;
- $$var = $value;
- }
- $Expires = $exp_year.'-'.$exp_month.'-'.$exp_day.' '.$exp_hour.':'.$exp_minute.':'.$exp_second;
- }
- else // force no expiry
- $exp_year = '0000';
- // custom Fields
- foreach ($adi_matrix_cfs as $index => $cf_name) {
- $custom_x = 'custom_'.$index;
- if (isset($data[$custom_x]))
- $$custom_x = $data[$custom_x];
- else
- $$custom_x = '';
- }
- // set the rest (not used by adi_matrix_update_article)
- $Body = '';
- $Body_html = '';
- $Excerpt = '';
- $Excerpt_html = '';
- $textile_body = $prefs['use_textile'];
- $textile_excerpt = $prefs['use_textile'];
- $Annotate = '0';
- $override_form = '';
- $AnnotateInvite = '';
- // package them all up
- $updates = compact($vars);
- if ($adi_matrix_debug) {
- echo '<b>Article '.$id.' data:</b>';
- dmp($updates);
- }
- // do some validation, textilation & slashing
- $incoming = array_map('assert_string',$updates);
- $incoming = textile_main_fields($incoming); // converts ampersands to & in titles
- extract(doSlash($incoming));
- if (isset($data['status']))
- extract(array_map('assert_int', array('Status' => $Status)));
- // title
- if (isset($data['title']))
- $titleq = "Title='$Title', ";
- else
- $titleq = '';
- // status
- $old_status = $new_status = $adi_matrix_articles[$id]['status'];
- if (isset($data['status'])) {
- $new_status = $Status;
- // tweak status according to privs
- if (!has_privs('article.publish') && $new_status >= STATUS_LIVE)
- $new_status = STATUS_PENDING;
- $statusq = 'Status='.doSlash($new_status).', ';
- if ($new_status >= STATUS_LIVE) // live & sticky articles only
- update_lastmod();
- }
- else
- $statusq = '';
- // section
- if (isset($data['section']))
- $sectionq = "Section='$Section', ";
- else
- $sectionq = '';
- // keywords
- if (isset($data['keywords']))
- $keywordsq = "Keywords='$Keywords', ";
- else
- $keywordsq = '';
- // article image
- if (isset($data['article_image']))
- $article_imageq = "Image='$Image', ";
- else
- $article_imageq = '';
- // categories
- if (isset($data['category1']))
- $categoryq = "Category1='$Category1', ";
- else
- $categoryq = '';
- if (isset($data['category2']))
- $categoryq .= "Category2='$Category2', ";
- else
- $categoryq .= '';
- // posted
- $postedq = '';
- if (isset($data['posted'])) {
- if ($publish_now)
- $postedq = "Posted=now(), ";
- else { // convert TXP date/time to DB timestamp
- $ts = strtotime($Posted);
- $date_error = ($ts === false || $ts === -1);
- if (!$date_error) {
- $when_ts = $ts - tz_offset($ts);
- $when = "from_unixtime($when_ts)";
- $postedq = "Posted=$when, ";
- }
- }
- }
- // expires
- $expiresq = '';
- if (isset($data['expires'])) {
- if ($exp_year == '0000')
- $expiry = 0;
- else { // convert TXP date/time to DB timestamp
- $ts = strtotime($Expires);
- $expiry = $ts - tz_offset($ts);
- }
- if ($expiry) {
- $date_error = ($ts === false || $ts === -1);
- if (!$date_error) {
- $expires = $ts - tz_offset($ts);
- $whenexpires = "from_unixtime($expires)";
- $expiresq = "Expires=$whenexpires, ";
- }
- }
- else
- $expiresq = "Expires=".NULLDATETIME.", ";
- }
- // custom fields
- $cfq = array();
- foreach($adi_matrix_cfs as $i => $cf_name) {
- $custom_x = "custom_{$i}";
- if (isset($data[$custom_x]))
- $cfq[] = "custom_$i = '".$$custom_x."'";
- }
- $cfq = implode(', ', $cfq);
- // update article in database
- $res = safe_update("textpattern",
- $titleq.$sectionq.$statusq.$keywordsq.$article_imageq.$categoryq.$postedq.$expiresq.(($cfq) ? $cfq.', ' : '')."LastMod=now(), LastModID='$txp_user'",
- "ID=$id",
- $adi_matrix_debug
- );
- if ($new_status >= STATUS_LIVE && $old_status < STATUS_LIVE)
- do_pings();
- if ($new_status >= STATUS_LIVE || $old_status >= STATUS_LIVE)
- update_lastmod();
- return $res;
- }
- function adi_matrix_update_articles($updates,$matrix_index) {
- // update articles
- $res = TRUE;
- if ($updates) {
- foreach ($updates as $id => $data)
- if ($id == 'new')
- $res = $res && adi_matrix_publish_article($data,$matrix_index);
- else
- $res = $res && adi_matrix_update_article($id,$data);
- }
- return $res;
- }
- function adi_matrix_article_defaults($matrix_index) {
- // default values for new article, adjusted for specified matrix
- global $adi_matrix_debug,$adi_matrix_list,$prefs,$adi_matrix_cfs,$adi_matrix_glz_cfs;
- // Article field $defaults['xx'] Who determines Default values
- // ------------- --------------- -------------- --------------
- // ID - MySQL generated on publish
- // Posted posted adi_matrix_article_defaults,user current date/time
- // Expires expires adi_matrix_article_defaults,user blank (converted to 0000-00-00 00:00:00 by adi_matrix_validate_post_data)
- // AuthorID - adi_matrix_publish_article current user
- // LastMod - adi_matrix_publish_article generated on publish
- // LastModID - adi_matrix_publish_article current user
- // Title title adi_matrix_article_defaults,user blank
- // Title_html - adi_matrix_publish_article blank
- // Body - adi_matrix_publish_article blank
- // Body_html - adi_matrix_publish_article blank
- // Excerpt - adi_matrix_publish_article blank
- // Excerpt_html - adi_matrix_publish_article blank
- // Image article_image adi_matrix_article_defaults,user blank
- // Category1 category1 adi_matrix_article_defaults,user criteria_category (if specific category set), blank
- // Category2 category2 adi_matrix_article_defaults,user blank
- // Annotate - adi_matrix_publish_article 0
- // AnnotateInvite - adi_matrix_publish_article blank
- // comments_count - MySQL default
- // Status status adi_matrix_article_defaults,user criteria_status (if set), "live"
- // textile_body - adi_matrix_publish_article 'use_textile' from $prefs
- // textile_excerpt - adi_matrix_publish_article 'use_textile' from $prefs
- // Section section adi_matrix_article_defaults first section from criteria_section (if set), 'default_section' from $prefs
- // override_form - adi_matrix_publish_article blank
- // Keywords keywords adi_matrix_article_defaults,user criteria_keywords (if set), blank
- // url_title - adi_matrix_publish_article generated-from-title
- // custom_x custom_x adi_matrix_article_defaults,user blank (if TXP CFs), GLZ default value (if GLZ CFs)
- // uid - adi_matrix_publish_article generated on publish
- // feed_time - adi_matrix_publish_article generated on publish
- $defaults = array();
- // title - blank
- $defaults['title'] = '';
- // status - from criteria (or live if not set)
- if ($adi_matrix_list[$matrix_index]['criteria_status'])
- $defaults['status'] = $adi_matrix_list[$matrix_index]['criteria_status'];
- else
- $defaults['status'] = '4';
- // article image - blank
- $defaults['article_image'] = '';
- // keywords - from criteria
- $defaults['keywords'] = $adi_matrix_list[$matrix_index]['criteria_keywords'];
- // category1 - if specific category set - assign it to cat1, otherwise leave it up to user (i.e. blank)
- if (($adi_matrix_list[$matrix_index]['criteria_category']) && (strpos($adi_matrix_list[$matrix_index]['criteria_category'],'!') === FALSE))
- $defaults['category1'] = $adi_matrix_list[$matrix_index]['criteria_category'];
- else
- $defaults['category1'] = '';
- // category2 - leave blank
- $defaults['category2'] = '';
- // posted
- $defaults['uposted'] = time();
- $defaults['posted'] = date("Y-m-d H:i:s",$defaults['uposted']);
- // expires - blank
- $defaults['uexpires'] = '';
- $defaults['expires'] = '';
- // section - $prefs default_section if blank, else first section on list if criteria set
- if ($adi_matrix_list[$matrix_index]['criteria_section']) {
- $sections = explode(',',$adi_matrix_list[$matrix_index]['criteria_section']);
- $defaults['section'] = $sections[0];
- }
- else
- $defaults['section'] = $prefs['default_section'];
- // custom fields - blank
- foreach ($adi_matrix_cfs as $index => $cf_name) {
- $custom_x = 'custom_'.$index;
- $defaults[$custom_x] = '';
- }
- // glean GLZ CF defaults & apply them
- if ($adi_matrix_glz_cfs) {
- $all_custom_sets = glz_custom_fields_MySQL("all"); // array indexed by custom_xx_set, value array(name,position,type)
- if ($adi_matrix_debug)
- echo "<b>GLZ custom field defaults</b>:".br;
- foreach ($all_custom_sets as $custom => $custom_set) { // index format is "custom_x_set"
- $arr_custom_field_values = glz_custom_fields_MySQL("values",$custom,'',array('custom_set_name' => $custom_set['name']));
- $default_value = glz_return_clean_default(glz_default_value($arr_custom_field_values));
- $custom_x = str_replace('_set','',$custom); // convert custom_x_set to custom_x
- if ($adi_matrix_debug) echo $custom_x.' default = '.'['.$default_value.']'.br;
- $defaults[$custom_x] = $default_value; // use GLZ default
- }
- }
- if ($adi_matrix_debug) {
- echo br.'<b>New article defaults:</b>';
- dmp($defaults);
- }
- return $defaults;
- }
- function adi_matrix_publish_article($data,$matrix_index) {
- // new article - based on article_post() from txp_article.php
- // update database with posted data or article defaults
- global $…
Large files files are truncated, but you can click here to view the full file