コード例 #1
0
ファイル: search.class.php プロジェクト: cheese1/ampache
 /**
  * constructor
  */
 public function __construct($id = null, $searchtype = 'song')
 {
     $this->searchtype = $searchtype;
     if ($id) {
         $info = $this->get_info($id);
         foreach ($info as $key => $value) {
             $this->{$key} = $value;
         }
         $this->rules = unserialize($this->rules);
     }
     // Define our basetypes
     $this->basetypes['numeric'][] = array('name' => 'gte', 'description' => T_('is greater than or equal to'), 'sql' => '>=');
     $this->basetypes['numeric'][] = array('name' => 'lte', 'description' => T_('is less than or equal to'), 'sql' => '<=');
     $this->basetypes['numeric'][] = array('name' => 'equal', 'description' => T_('is'), 'sql' => '<=>');
     $this->basetypes['numeric'][] = array('name' => 'ne', 'description' => T_('is not'), 'sql' => '<>');
     $this->basetypes['numeric'][] = array('name' => 'gt', 'description' => T_('is greater than'), 'sql' => '>');
     $this->basetypes['numeric'][] = array('name' => 'lt', 'description' => T_('is less than'), 'sql' => '<');
     $this->basetypes['boolean'][] = array('name' => 'true', 'description' => T_('is true'));
     $this->basetypes['boolean'][] = array('name' => 'false', 'description' => T_('is false'));
     $this->basetypes['text'][] = array('name' => 'contain', 'description' => T_('contains'), 'sql' => 'LIKE', 'preg_match' => array('/^/', '/$/'), 'preg_replace' => array('%', '%'));
     $this->basetypes['text'][] = array('name' => 'notcontain', 'description' => T_('does not contain'), 'sql' => 'NOT LIKE', 'preg_match' => array('/^/', '/$/'), 'preg_replace' => array('%', '%'));
     $this->basetypes['text'][] = array('name' => 'start', 'description' => T_('starts with'), 'sql' => 'LIKE', 'preg_match' => '/$/', 'preg_replace' => '%');
     $this->basetypes['text'][] = array('name' => 'end', 'description' => T_('ends with'), 'sql' => 'LIKE', 'preg_match' => '/^/', 'preg_replace' => '%');
     $this->basetypes['text'][] = array('name' => 'equal', 'description' => T_('is'), 'sql' => '=');
     $this->basetypes['text'][] = array('name' => 'sounds', 'description' => T_('sounds like'), 'sql' => 'SOUNDS LIKE');
     $this->basetypes['text'][] = array('name' => 'notsounds', 'description' => T_('does not sound like'), 'sql' => 'NOT SOUNDS LIKE');
     $this->basetypes['boolean_numeric'][] = array('name' => 'equal', 'description' => T_('is'), 'sql' => '<=>');
     $this->basetypes['boolean_numeric'][] = array('name' => 'ne', 'description' => T_('is not'), 'sql' => '<>');
     $this->basetypes['boolean_subsearch'][] = array('name' => 'equal', 'description' => T_('is'), 'sql' => '');
     $this->basetypes['boolean_subsearch'][] = array('name' => 'ne', 'description' => T_('is not'), 'sql' => 'NOT');
     $this->basetypes['date'][] = array('name' => 'lt', 'description' => T_('before'), 'sql' => '<');
     $this->basetypes['date'][] = array('name' => 'gt', 'description' => T_('after'), 'sql' => '>');
     $this->basetypes['multiple'] = array_merge($this->basetypes['text'], $this->basetypes['numeric']);
     switch ($searchtype) {
         case 'song':
             $this->types[] = array('name' => 'anywhere', 'label' => T_('Any searchable text'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'title', 'label' => T_('Title'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'album', 'label' => T_('Album'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'artist', 'label' => T_('Artist'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'composer', 'label' => T_('Composer'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'comment', 'label' => T_('Comment'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'label', 'label' => T_('Label'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'tag', 'label' => T_('Tag'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'album_tag', 'label' => T_('Album tag'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'file', 'label' => T_('Filename'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'year', 'label' => T_('Year'), 'type' => 'numeric', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'time', 'label' => T_('Length (in minutes)'), 'type' => 'numeric', 'widget' => array('input', 'text'));
             if (AmpConfig::get('ratings')) {
                 $this->types[] = array('name' => 'rating', 'label' => T_('Rating'), 'type' => 'numeric', 'widget' => array('select', array('1 Star', '2 Stars', '3 Stars', '4 Stars', '5 Stars')));
             }
             if (AmpConfig::get('show_played_times')) {
                 $this->types[] = array('name' => 'played_times', 'label' => T_('# Played'), 'type' => 'numeric', 'widget' => array('input', 'text'));
             }
             $this->types[] = array('name' => 'bitrate', 'label' => T_('Bitrate'), 'type' => 'numeric', 'widget' => array('select', array('32', '40', '48', '56', '64', '80', '96', '112', '128', '160', '192', '224', '256', '320')));
             $this->types[] = array('name' => 'played', 'label' => T_('Played'), 'type' => 'boolean', 'widget' => array('input', 'hidden'));
             $this->types[] = array('name' => 'added', 'label' => T_('Added'), 'type' => 'date', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'updated', 'label' => T_('Updated'), 'type' => 'date', 'widget' => array('input', 'text'));
             $catalogs = array();
             foreach (Catalog::get_catalogs() as $catid) {
                 $catalog = Catalog::create_from_id($catid);
                 $catalog->format();
                 $catalogs[$catid] = $catalog->f_name;
             }
             $this->types[] = array('name' => 'catalog', 'label' => T_('Catalog'), 'type' => 'boolean_numeric', 'widget' => array('select', $catalogs));
             $playlists = array();
             foreach (Playlist::get_playlists() as $playlistid) {
                 $playlist = new Playlist($playlistid);
                 $playlist->format();
                 $playlists[$playlistid] = $playlist->f_name;
             }
             $this->types[] = array('name' => 'playlist', 'label' => T_('Playlist'), 'type' => 'boolean_numeric', 'widget' => array('select', $playlists));
             $this->types[] = array('name' => 'playlist_name', 'label' => T_('Playlist Name'), 'type' => 'text', 'widget' => array('input', 'text'));
             $playlists = array();
             foreach (Search::get_searches() as $playlistid) {
                 // Slightly different from the above so we don't instigate
                 // a vicious loop.
                 $playlists[$playlistid] = Search::get_name_byid($playlistid);
             }
             $this->types[] = array('name' => 'smartplaylist', 'label' => T_('Smart Playlist'), 'type' => 'boolean_subsearch', 'widget' => array('select', $playlists));
             $metadataFields = array();
             $metadataFieldRepository = new \Lib\Metadata\Repository\MetadataField();
             foreach ($metadataFieldRepository->findAll() as $metadata) {
                 $metadataFields[$metadata->getId()] = $metadata->getName();
             }
             $this->types[] = array('name' => 'metadata', 'label' => T_('Metadata'), 'type' => 'multiple', 'subtypes' => $metadataFields, 'widget' => array('subtypes', array('input', 'text')));
             $licenses = array();
             foreach (License::get_licenses() as $license_id) {
                 $license = new License($license_id);
                 $licenses[$license_id] = $license->name;
             }
             if (AmpConfig::get('licensing')) {
                 $this->types[] = array('name' => 'license', 'label' => T_('Music License'), 'type' => 'boolean_numeric', 'widget' => array('select', $licenses));
             }
             break;
         case 'album':
             $this->types[] = array('name' => 'title', 'label' => T_('Title'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'artist', 'label' => T_('Artist'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'year', 'label' => T_('Year'), 'type' => 'numeric', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'image width', 'label' => T_('Image Width'), 'type' => 'numeric', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'image height', 'label' => T_('Image Height'), 'type' => 'numeric', 'widget' => array('input', 'text'));
             if (AmpConfig::get('ratings')) {
                 $this->types[] = array('name' => 'rating', 'label' => T_('Rating'), 'type' => 'numeric', 'widget' => array('select', array('1 Star', '2 Stars', '3 Stars', '4 Stars', '5 Stars')));
             }
             $catalogs = array();
             foreach (Catalog::get_catalogs() as $catid) {
                 $catalog = Catalog::create_from_id($catid);
                 $catalog->format();
                 $catalogs[$catid] = $catalog->f_name;
             }
             $this->types[] = array('name' => 'catalog', 'label' => T_('Catalog'), 'type' => 'boolean_numeric', 'widget' => array('select', $catalogs));
             $this->types[] = array('name' => 'tag', 'label' => T_('Tag'), 'type' => 'text', 'widget' => array('input', 'text'));
             break;
         case 'video':
             $this->types[] = array('name' => 'filename', 'label' => T_('Filename'), 'type' => 'text', 'widget' => array('input', 'text'));
             break;
         case 'artist':
             $this->types[] = array('name' => 'name', 'label' => T_('Name'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'yearformed', 'label' => T_('Year'), 'type' => 'numeric', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'placeformed', 'label' => T_('Place'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'tag', 'label' => T_('Tag'), 'type' => 'text', 'widget' => array('input', 'text'));
             break;
         case 'playlist':
             $this->types[] = array('name' => 'name', 'label' => T_('Name'), 'type' => 'text', 'widget' => array('input', 'text'));
             break;
         case 'label':
             $this->types[] = array('name' => 'name', 'label' => T_('Name'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'category', 'label' => T_('Category'), 'type' => 'text', 'widget' => array('input', 'text'));
             break;
         case 'user':
             $this->types[] = array('name' => 'username', 'label' => T_('Username'), 'type' => 'text', 'widget' => array('input', 'text'));
             break;
     }
     // end switch on searchtype
 }
コード例 #2
0
ファイル: preferences.php プロジェクト: cheese1/ampache
/**
 * create_preference_input
 * takes the key and then creates the correct type of input for updating it
 */
function create_preference_input($name, $value)
{
    if (!Preference::has_access($name)) {
        if ($value == '1') {
            echo "Enabled";
        } elseif ($value == '0') {
            echo "Disabled";
        } else {
            if (preg_match('/_pass$/', $name) || preg_match('/_api_key$/', $name)) {
                echo "******";
            } else {
                echo $value;
            }
        }
        return;
    }
    // if we don't have access to it
    switch ($name) {
        case 'display_menu':
        case 'download':
        case 'quarantine':
        case 'upload':
        case 'access_list':
        case 'lock_songs':
        case 'xml_rpc':
        case 'force_http_play':
        case 'no_symlinks':
        case 'use_auth':
        case 'access_control':
        case 'allow_stream_playback':
        case 'allow_democratic_playback':
        case 'allow_localplay_playback':
        case 'demo_mode':
        case 'condPL':
        case 'rio_track_stats':
        case 'rio_global_stats':
        case 'direct_link':
        case 'ajax_load':
        case 'now_playing_per_user':
        case 'show_played_times':
        case 'song_page_title':
        case 'subsonic_backend':
        case 'plex_backend':
        case 'webplayer_flash':
        case 'webplayer_html5':
        case 'allow_personal_info_now':
        case 'allow_personal_info_recent':
        case 'allow_personal_info_time':
        case 'allow_personal_info_agent':
        case 'ui_fixed':
        case 'autoupdate':
        case 'webplayer_confirmclose':
        case 'webplayer_pausetabs':
        case 'stream_beautiful_url':
        case 'share':
        case 'share_social':
        case 'broadcast_by_default':
        case 'album_group':
        case 'topmenu':
        case 'demo_clear_sessions':
        case 'show_donate':
        case 'allow_upload':
        case 'upload_subdir':
        case 'upload_user_artist':
        case 'upload_allow_edit':
        case 'daap_backend':
        case 'upnp_backend':
        case 'album_release_type':
        case 'home_moment_albums':
        case 'home_moment_videos':
        case 'home_recently_played':
        case 'home_now_playing':
        case 'browser_notify':
        case 'allow_video':
        case 'geolocation':
        case 'webplayer_aurora':
        case 'upload_allow_remove':
        case 'webdav_backend':
        case 'notify_email':
            $is_true = '';
            $is_false = '';
            if ($value == '1') {
                $is_true = "selected=\"selected\"";
            } else {
                $is_false = "selected=\"selected\"";
            }
            echo "<select name=\"{$name}\">\n";
            echo "\t<option value=\"1\" {$is_true}>" . T_("Enable") . "</option>\n";
            echo "\t<option value=\"0\" {$is_false}>" . T_("Disable") . "</option>\n";
            echo "</select>\n";
            break;
        case 'upload_catalog':
            show_catalog_select('upload_catalog', $value, '', true);
            break;
        case 'play_type':
            $is_localplay = '';
            $is_democratic = '';
            $is_web_player = '';
            $is_stream = '';
            if ($value == 'localplay') {
                $is_localplay = 'selected="selected"';
            } elseif ($value == 'democratic') {
                $is_democratic = 'selected="selected"';
            } elseif ($value == 'web_player') {
                $is_web_player = 'selected="selected"';
            } else {
                $is_stream = "selected=\"selected\"";
            }
            echo "<select name=\"{$name}\">\n";
            echo "\t<option value=\"\">" . T_('None') . "</option>\n";
            if (AmpConfig::get('allow_stream_playback')) {
                echo "\t<option value=\"stream\" {$is_stream}>" . T_('Stream') . "</option>\n";
            }
            if (AmpConfig::get('allow_democratic_playback')) {
                echo "\t<option value=\"democratic\" {$is_democratic}>" . T_('Democratic') . "</option>\n";
            }
            if (AmpConfig::get('allow_localplay_playback')) {
                echo "\t<option value=\"localplay\" {$is_localplay}>" . T_('Localplay') . "</option>\n";
            }
            echo "\t<option value=\"web_player\" {$is_web_player}>" . _('Web Player') . "</option>\n";
            echo "</select>\n";
            break;
        case 'playlist_type':
            $var_name = $value . "_type";
            ${$var_name} = "selected=\"selected\"";
            echo "<select name=\"{$name}\">\n";
            echo "\t<option value=\"m3u\" {$m3u_type}>" . T_('M3U') . "</option>\n";
            echo "\t<option value=\"simple_m3u\" {$simple_m3u_type}>" . T_('Simple M3U') . "</option>\n";
            echo "\t<option value=\"pls\" {$pls_type}>" . T_('PLS') . "</option>\n";
            echo "\t<option value=\"asx\" {$asx_type}>" . T_('Asx') . "</option>\n";
            echo "\t<option value=\"ram\" {$ram_type}>" . T_('RAM') . "</option>\n";
            echo "\t<option value=\"xspf\" {$xspf_type}>" . T_('XSPF') . "</option>\n";
            echo "</select>\n";
            break;
        case 'lang':
            $languages = get_languages();
            echo '<select name="' . $name . '">' . "\n";
            foreach ($languages as $lang => $name) {
                $selected = $lang == $value ? 'selected="selected"' : '';
                echo "\t<option value=\"{$lang}\" " . $selected . ">{$name}</option>\n";
            }
            // end foreach
            echo "</select>\n";
            break;
        case 'localplay_controller':
            $controllers = Localplay::get_controllers();
            echo "<select name=\"{$name}\">\n";
            echo "\t<option value=\"\">" . T_('None') . "</option>\n";
            foreach ($controllers as $controller) {
                if (!Localplay::is_enabled($controller)) {
                    continue;
                }
                $is_selected = '';
                if ($value == $controller) {
                    $is_selected = 'selected="selected"';
                }
                echo "\t<option value=\"" . $controller . "\" {$is_selected}>" . ucfirst($controller) . "</option>\n";
            }
            // end foreach
            echo "</select>\n";
            break;
        case 'localplay_level':
            $is_user = '';
            $is_admin = '';
            $is_manager = '';
            if ($value == '25') {
                $is_user = '******';
            } elseif ($value == '100') {
                $is_admin = 'selected="selected"';
            } elseif ($value == '50') {
                $is_manager = 'selected="selected"';
            }
            echo "<select name=\"{$name}\">\n";
            echo "<option value=\"0\">" . T_('Disabled') . "</option>\n";
            echo "<option value=\"25\" {$is_user}>" . T_('User') . "</option>\n";
            echo "<option value=\"50\" {$is_manager}>" . T_('Manager') . "</option>\n";
            echo "<option value=\"100\" {$is_admin}>" . T_('Admin') . "</option>\n";
            echo "</select>\n";
            break;
        case 'theme_name':
            $themes = get_themes();
            echo "<select name=\"{$name}\">\n";
            foreach ($themes as $theme) {
                $is_selected = "";
                if ($value == $theme['path']) {
                    $is_selected = "selected=\"selected\"";
                }
                echo "\t<option value=\"" . $theme['path'] . "\" {$is_selected}>" . $theme['name'] . "</option>\n";
            }
            // foreach themes
            echo "</select>\n";
            break;
        case 'theme_color':
            // This include a two-step configuration (first change theme and save, then change theme color and save)
            $theme_cfg = get_theme(AmpConfig::get('theme_name'));
            if ($theme_cfg !== null) {
                echo "<select name=\"{$name}\">\n";
                foreach ($theme_cfg['colors'] as $color) {
                    $is_selected = "";
                    if ($value == strtolower($color)) {
                        $is_selected = "selected=\"selected\"";
                    }
                    echo "\t<option value=\"" . strtolower($color) . "\" {$is_selected}>" . $color . "</option>\n";
                }
                // foreach themes
                echo "</select>\n";
            }
            break;
        case 'playlist_method':
            ${$value} = ' selected="selected"';
            echo "<select name=\"{$name}\">\n";
            echo "\t<option value=\"send\"{$send}>" . T_('Send on Add') . "</option>\n";
            echo "\t<option value=\"send_clear\"{$send_clear}>" . T_('Send and Clear on Add') . "</option>\n";
            echo "\t<option value=\"clear\"{$clear}>" . T_('Clear on Send') . "</option>\n";
            echo "\t<option value=\"default\"{$default}>" . T_('Default') . "</option>\n";
            echo "</select>\n";
            break;
        case 'transcode':
            ${$value} = ' selected="selected"';
            echo "<select name=\"{$name}\">\n";
            echo "\t<option value=\"never\"{$never}>" . T_('Never') . "</option>\n";
            echo "\t<option value=\"default\"{$default}>" . T_('Default') . "</option>\n";
            echo "\t<option value=\"always\"{$always}>" . T_('Always') . "</option>\n";
            echo "</select>\n";
            break;
        case 'show_lyrics':
            $is_true = '';
            $is_false = '';
            if ($value == '1') {
                $is_true = "selected=\"selected\"";
            } else {
                $is_false = "selected=\"selected\"";
            }
            echo "<select name=\"{$name}\">\n";
            echo "\t<option value=\"1\" {$is_true}>" . T_("Enable") . "</option>\n";
            echo "\t<option value=\"0\" {$is_false}>" . T_("Disable") . "</option>\n";
            echo "</select>\n";
            break;
        case 'album_sort':
            $is_sort_year_asc = '';
            $is_sort_year_desc = '';
            $is_sort_name_asc = '';
            $is_sort_name_desc = '';
            $is_sort_default = '';
            if ($value == 'year_asc') {
                $is_sort_year_asc = 'selected="selected"';
            } elseif ($value == 'year_desc') {
                $is_sort_year_desc = 'selected="selected"';
            } elseif ($value == 'name_asc') {
                $is_sort_name_asc = 'selected="selected"';
            } elseif ($value == 'name_desc') {
                $is_sort_name_desc = 'selected="selected"';
            } else {
                $is_sort_default = 'selected="selected"';
            }
            echo "<select name=\"{$name}\">\n";
            echo "\t<option value=\"default\" {$is_sort_default}>" . T_('Default') . "</option>\n";
            echo "\t<option value=\"year_asc\" {$is_sort_year_asc}>" . T_('Year ascending') . "</option>\n";
            echo "\t<option value=\"year_desc\" {$is_sort_year_desc}>" . T_('Year descending') . "</option>\n";
            echo "\t<option value=\"name_asc\" {$is_sort_name_asc}>" . T_('Name ascending') . "</option>\n";
            echo "\t<option value=\"name_desc\" {$is_sort_name_desc}>" . T_('Name descending') . "</option>\n";
            echo "</select>\n";
            break;
        case 'disabled_custom_metadata_fields':
            $ids = explode(',', $value);
            $options = array();
            $fieldRepository = new \Lib\Metadata\Repository\MetadataField();
            foreach ($fieldRepository->findAll() as $field) {
                $selected = in_array($field->getId(), $ids) ? ' selected="selected"' : '';
                $options[] = '<option value="' . $field->getId() . '"' . $selected . '>' . $field->getName() . '</option>';
            }
            echo '<select multiple size="5" name="' . $name . '[]">' . implode("\n", $options) . '</select>';
            break;
        case 'lastfm_grant_link':
        case 'librefm_grant_link':
            // construct links for granting access Ampache application to Last.fm and Libre.fm
            $plugin_name = ucfirst(str_replace('_grant_link', '', $name));
            $plugin = new Plugin($plugin_name);
            $url = $plugin->_plugin->url;
            $api_key = rawurlencode(AmpConfig::get('lastfm_api_key'));
            $callback = rawurlencode(AmpConfig::get('web_path') . '/preferences.php?tab=plugins&action=grant&plugin=' . $plugin_name);
            echo "<a href='{$url}/api/auth/?api_key={$api_key}&cb={$callback}'>" . UI::get_icon('plugin', T_("Click for grant Ampache to ") . $plugin_name) . '</a>';
            break;
        default:
            if (preg_match('/_pass$/', $name)) {
                echo '<input type="password" name="' . $name . '" value="******" />';
            } else {
                echo '<input type="text" name="' . $name . '" value="' . $value . '" />';
            }
            break;
    }
}