Skip to content

Instantly share code, notes, and snippets.

@gerhard
Created October 9, 2009 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gerhard/205789 to your computer and use it in GitHub Desktop.
Save gerhard/205789 to your computer and use it in GitHub Desktop.
<?php
//-------------------------------------------------------------
function get_prefs()
{
global $txp_user;
$out = array();
// get current user's private prefs
if ($txp_user) {
$r = safe_rows_start('name, val', 'txp_prefs', 'prefs_id=1 AND user_name=\''.doSlash($txp_user).'\'');
if ($r) {
while ($a = nextRow($r)) {
$out[$a['name']] = $a['val'];
}
}
}
// get global prefs, eventually override equally named user prefs.
$r = safe_rows_start('name, val', 'txp_prefs', 'prefs_id=1 AND user_name=\'\'');
if ($r) {
while ($a = nextRow($r)) {
$out[$a['name']] = $a['val'];
}
}
return $out;
}
<?php
array (
'pane_article_more_visible' => '0',
'admin_sort_column' => 'name',
'admin_sort_dir' => 'asc',
'log_sort_column' => 'time',
'log_sort_dir' => 'desc',
'plugin_sort_column' => 'name',
'plugin_sort_dir' => 'asc',
'pane_article_advanced_visible' => '1',
'article_sort_column' => 'posted',
'article_sort_dir' => 'desc',
'pane_article_recent_visible' => '0',
'image_sort_column' => 'id',
'image_sort_dir' => 'desc',
'file_sort_column' => 'filename',
'file_sort_dir' => 'asc',
'link_sort_column' => 'name',
'link_sort_dir' => 'asc',
'smd_bio_meta_sort_column' => 'name',
'smd_bio_meta_sort_dir' => 'asc',
'prefs_id' => '1',
'sitename' => 'My Site',
'siteurl' => 'localhost/textpattern-4.2.0',
'site_slogan' => 'My pithy slogan',
'language' => 'en-gb',
'url_mode' => '1',
'timeoffset' => '0',
'comments_on_default' => '0',
'comments_default_invite' => 'Comment',
'comments_mode' => '0',
'comments_disabled_after' => '42',
'use_textile' => '1',
'ping_weblogsdotcom' => '0',
'rss_how_many' => '5',
'logging' => 'all',
'use_comments' => '1',
'use_categories' => '1',
'use_sections' => '1',
'send_lastmod' => '1',
'path_from_root' => '/',
'lastmod' => '2009-09-26 09:21:22',
'comments_dateformat' => '%b %Oe, %I:%M %p',
'dateformat' => 'since',
'archive_dateformat' => '%b %Oe, %I:%M %p',
'comments_moderate' => '1',
'img_dir' => 'images',
'comments_disallow_images' => '0',
'comments_sendmail' => '0',
'file_max_upload_size' => '2000000',
'path_to_site' => '/var/www/textpattern-4.2.0',
'timezone_key' => '',
'default_event' => 'article',
'auto_dst' => '0',
'permlink_mode' => 'messy',
'comments_are_ol' => '1',
'is_dst' => '0',
'locale' => 'en_GB.UTF-8',
'tempdir' => '/tmp',
'file_base_path' => '/var/www/textpattern-4.2.0/files',
'blog_uid' => '3f9ad4815ccd69f77b3b2c115cbd6287',
'blog_mail_uid' => 'gerhard@lazu.co.uk',
'blog_time_uid' => '2005',
'edit_raw_css_by_default' => '1',
'allow_page_php_scripting' => '1',
'allow_article_php_scripting' => '1',
'allow_raw_php_scripting' => '0',
'comments_use_fat_textile' => '0',
'show_article_category_count' => '1',
'show_comment_count_in_feed' => '1',
'syndicate_body_or_excerpt' => '1',
'include_email_atom' => '1',
'comment_means_site_updated' => '1',
'never_display_email' => '0',
'comments_require_name' => '1',
'comments_require_email' => '1',
'articles_use_excerpts' => '1',
'allow_form_override' => '1',
'attach_titles_to_permalinks' => '1',
'permalink_title_format' => '1',
'expire_logs_after' => '7',
'use_plugins' => '1',
'custom_2_set' => 'custom2',
'custom_1_set' => 'custom1',
'custom_3_set' => 'dp',
'custom_4_set' => 'custom4',
'custom_5_set' => '',
'custom_7_set' => '',
'custom_8_set' => '',
'custom_9_set' => 'select_field',
'custom_10_set' => 'radio',
'ping_textpattern_com' => '1',
'use_dns' => '1',
'admin_side_plugins' => '1',
'comment_nofollow' => '1',
'use_mail_on_feeds_id' => '0',
'max_url_len' => '200',
'spam_blacklists' => 'sbl.spamhaus.org',
'override_emailcharset' => '0',
'production_status' => 'debug',
'comments_auto_append' => '1',
'dbupdatetime' => '1252786069',
'version' => '4.2.0',
'gmtoffset' => '+3600',
'plugin_cache_dir' => '/var/www/textpattern-4.2.0/scripts',
'textile_updated' => '1',
'title_no_widow' => '1',
'lastmod_keepalive' => '0',
'enable_xmlrpc_server' => '0',
'smtp_from' => '',
'theme_name' => 'classic',
'publish_expired_articles' => '0',
'searchable_article_fields' => 'Title, Body',
'max_custom_fields' => '11',
'custom_11_set' => 'my new custom field',
'custom_12_set' => 'another custom field',
'migrated' => '1',
'datepicker_first_day' => '1',
'values_ordering' => 'custom',
'glz_custom_fields_migrated' => '1',
'datepicker_format' => 'dd/mm/yyyy',
)
<?php
//-------------------------------------------------------------
function get_prefs()
{
global $txp_user;
$out = array();
// get current user's private prefs
if ($txp_user) {
$r = safe_rows_start('name, val, event', 'txp_prefs', 'prefs_id=1 AND user_name=\''.doSlash($txp_user).'\'');
if ($r) {
while ($a = nextRow($r)) {
$out[$a['event']][$a['name']] = $a['val'];
}
}
}
// get global prefs, eventually override equally named user prefs.
$r = safe_rows_start('name, val, event', 'txp_prefs', 'prefs_id=1 AND user_name=\'\'');
if ($r) {
while ($a = nextRow($r)) {
$out[$a['event']][$a['name']] = $a['val'];
}
}
return $out;
}
<?php
array (
'publish' =>
array (
'prefs_id' => '1',
'sitename' => 'My Site',
'siteurl' => 'localhost/textpattern-4.2.0',
'site_slogan' => 'My pithy slogan',
'language' => 'en-gb',
'url_mode' => '1',
'timeoffset' => '0',
'use_textile' => '1',
'ping_weblogsdotcom' => '0',
'logging' => 'all',
'use_comments' => '1',
'use_categories' => '1',
'use_sections' => '1',
'send_lastmod' => '1',
'path_from_root' => '/',
'lastmod' => '2009-09-26 09:21:22',
'dateformat' => 'since',
'archive_dateformat' => '%b %Oe, %I:%M %p',
'path_to_site' => '/var/www/textpattern-4.2.0',
'timezone_key' => '',
'auto_dst' => '0',
'permlink_mode' => 'messy',
'is_dst' => '0',
'locale' => 'en_GB.UTF-8',
'blog_uid' => '3f9ad4815ccd69f77b3b2c115cbd6287',
'blog_mail_uid' => 'gerhard@lazu.co.uk',
'blog_time_uid' => '2005',
'allow_page_php_scripting' => '1',
'allow_article_php_scripting' => '1',
'allow_raw_php_scripting' => '0',
'articles_use_excerpts' => '1',
'allow_form_override' => '1',
'attach_titles_to_permalinks' => '1',
'permalink_title_format' => '1',
'expire_logs_after' => '7',
'use_plugins' => '1',
'ping_textpattern_com' => '1',
'use_dns' => '1',
'admin_side_plugins' => '1',
'max_url_len' => '200',
'production_status' => 'debug',
'dbupdatetime' => '1252786069',
'version' => '4.2.0',
'gmtoffset' => '+3600',
'textile_updated' => '1',
'title_no_widow' => '1',
'lastmod_keepalive' => '0',
'publish_expired_articles' => '0',
'searchable_article_fields' => 'Title, Body',
'max_custom_fields' => '11',
),
'comments' =>
array (
'comments_on_default' => '0',
'comments_default_invite' => 'Comment',
'comments_mode' => '0',
'comments_disabled_after' => '42',
'comments_dateformat' => '%b %Oe, %I:%M %p',
'comments_moderate' => '1',
'comments_disallow_images' => '0',
'comments_sendmail' => '0',
'comments_are_ol' => '1',
'comments_use_fat_textile' => '0',
'comment_means_site_updated' => '1',
'never_display_email' => '0',
'comments_require_name' => '1',
'comments_require_email' => '1',
'comment_nofollow' => '1',
'spam_blacklists' => 'sbl.spamhaus.org',
'comments_auto_append' => '1',
),
'feeds' =>
array (
'rss_how_many' => '5',
'show_comment_count_in_feed' => '1',
'syndicate_body_or_excerpt' => '1',
'include_email_atom' => '1',
'use_mail_on_feeds_id' => '0',
),
'admin' =>
array (
'img_dir' => 'images',
'file_max_upload_size' => '2000000',
'default_event' => 'article',
'tempdir' => '/tmp',
'file_base_path' => '/var/www/textpattern-4.2.0/files',
'override_emailcharset' => '0',
'plugin_cache_dir' => '/var/www/textpattern-4.2.0/scripts',
'enable_xmlrpc_server' => '0',
'smtp_from' => '',
'theme_name' => 'classic',
'admin_sort_column' => 'name',
'admin_sort_dir' => 'asc',
'glz_custom_fields_migrated' => '1',
),
'css' =>
array (
'edit_raw_css_by_default' => '1',
),
'category' =>
array (
'show_article_category_count' => '1',
),
'custom' =>
array (
'custom_2_set' => 'custom2',
'custom_1_set' => 'custom1',
'custom_3_set' => 'dp',
'custom_4_set' => 'custom4',
'custom_5_set' => '',
'custom_7_set' => '',
'custom_8_set' => '',
'custom_9_set' => 'select_field',
'custom_10_set' => 'radio',
'custom_11_set' => 'my new custom field',
'custom_12_set' => 'another custom field',
),
'article' =>
array (
'pane_article_more_visible' => '0',
'pane_article_advanced_visible' => '1',
'pane_article_recent_visible' => '0',
),
'log' =>
array (
'log_sort_column' => 'time',
'log_sort_dir' => 'desc',
),
'plugin' =>
array (
'plugin_sort_column' => 'name',
'plugin_sort_dir' => 'asc',
),
'list' =>
array (
'article_sort_column' => 'posted',
'article_sort_dir' => 'desc',
),
'image' =>
array (
'image_sort_column' => 'id',
'image_sort_dir' => 'desc',
),
'file' =>
array (
'file_sort_column' => 'filename',
'file_sort_dir' => 'asc',
),
'link' =>
array (
'link_sort_column' => 'name',
'link_sort_dir' => 'asc',
),
'glz_custom_f' =>
array (
'migrated' => '1',
'datepicker_first_day' => '1',
'values_ordering' => 'custom',
'datepicker_format' => 'dd/mm/yyyy',
),
)
<?php
// current function
function getCustomFields()
{
global $prefs;
$max = get_pref('max_custom_fields', 10);
$out = array();
for ($i = 1; $i <= $max; $i++) {
if (!empty($prefs['custom_'.$i.'_set'])) {
$out[$i] = strtolower($prefs['custom_'.$i.'_set']);
}
}
return $out;
}
// new function
function getCustomFields()
{
global $prefs;
$ordered_prefs = get_prefs(array('ordered' => true));
$out = array();
foreach ( $ordered_prefs['custom'] as $name => $value ) {
// is it necessary to assign the right key to $out via $i?
if (!empty($prefs[$name]))
$out[] = strtolower($value);
}
return $out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment