コード例 #1
0
ファイル: Output.php プロジェクト: parsonsc/dofe
 static function ParseSorting($sort = '', $for_cat = false)
 {
     if ($for_cat) {
         $fields =& self::$sort_fields_cat;
     } else {
         $fields =& self::$sort_fields_file;
     }
     if (is_null($fields)) {
         $fields = array_keys($for_cat ? get_class_vars('WPFB_Category') : array_merge(get_class_vars('WPFB_File'), WPFB_Core::GetCustomFields(true)));
     }
     if (!$for_cat && !empty($_REQUEST['wpfb_file_sort'])) {
         $sort = $_REQUEST['wpfb_file_sort'];
     }
     $sort = str_replace(array('&gt;', '&lt;'), array('>', '<'), $sort);
     if (($p = strpos($sort, ',')) !== false) {
         $sort = substr($sort, 0, $p);
     }
     $desc = $for_cat ? WPFB_Core::$settings->filelist_sorting_dir : false;
     if ($sort && $sort[0] == '<') {
         $desc = false;
         $sort = substr($sort, 1);
     } elseif ($sort && $sort[0] == '>') {
         $desc = true;
         $sort = substr($sort, 1);
     }
     if (!$sort || !in_array($sort, $fields)) {
         $sort = $for_cat ? 'cat_name' : WPFB_Core::$settings->filelist_sorting;
     }
     return array($sort, $desc ? 'DESC' : 'ASC');
 }
コード例 #2
0
ファイル: Search.php プロジェクト: parsonsc/dofe
 static function SearchWhereSql($search_id3 = false, $s = null)
 {
     global $wp_query, $wpdb;
     static $search_fields;
     if (empty($search_fields)) {
         $search_fields = array_merge(array('file_name', 'file_thumbnail', 'file_display_name', 'file_description', 'file_tags', 'file_requirement', 'file_version', 'file_author', 'file_language', 'file_platform', 'file_license'), array_keys(WPFB_Core::GetCustomFields(true)));
     }
     if (empty($s)) {
         $s = empty($wp_query->query_vars['s']) ? empty($_GET['s']) ? null : stripslashes($_GET['s']) : $wp_query->query_vars['s'];
         if (empty($s)) {
             return null;
         }
     }
     $exact = !empty($wp_query->query_vars['exact']);
     $p = $exact ? '' : '%';
     $search_terms = self::getSearchTerms($s);
     $where = "(1";
     // TODO: search fields with match...
     foreach ($search_terms as $term) {
         $where .= ($not = $term[0] === '-') ? " AND NOT (" : " AND (";
         if ($not) {
             $term = substr($term, 1);
         }
         $wc = strpos($term, '*') !== false;
         // check for wildcard
         $or = '';
         foreach ($search_fields as $sf) {
             $col = "{$wpdb->wpfilebase_files}.{$sf}";
             $where .= " {$or}({$col} LIKE '" . ($wc ? str_replace('*', '%', $term) : "{$p}{$term}{$p}") . "')";
             if (empty($or)) {
                 $or = 'OR ';
             }
         }
         // !$not -> dont exclude from id3 files
         if (!$not && $search_id3) {
             $where .= " OR ({$wpdb->wpfilebase_files_id3}.keywords LIKE '{$p}{$term}{$p}')";
         }
         // TODO: MATCH func here
         $where .= ") ";
     }
     $where .= ")";
     return $where;
 }
コード例 #3
0
ファイル: FileListTable.php プロジェクト: parsonsc/dofe
 function prepare_items()
 {
     global $wpdb;
     $columns = $this->get_columns();
     $hidden = array();
     $sortable = $this->get_sortable_columns();
     $this->_column_headers = array($columns, $hidden, $sortable);
     $this->process_bulk_action();
     $pagenum = $this->get_pagenum();
     if (!isset($filesperpage) || $filesperpage < 0) {
         $filesperpage = 50;
     }
     $pagestart = ($pagenum - 1) * $filesperpage;
     $where = $this->get_file_where_cond(empty($_REQUEST['view']) ? null : $_REQUEST['view']);
     $order = "{$wpdb->wpfilebase_files}." . (!empty($_REQUEST['orderby']) && in_array($_REQUEST['orderby'], array_merge(array_keys(get_class_vars('WPFB_File')), array_keys(WPFB_Core::GetCustomFields(true)))) ? $_REQUEST['orderby'] . " " . (!empty($_REQUEST['order']) && $_REQUEST['order'] == "desc" ? "DESC" : "ASC") : "file_id DESC");
     $total_items = WPFB_File::GetNumFiles2($where, 'edit');
     $files = WPFB_File::GetFiles2($where, 'edit', $order, $filesperpage, $pagestart);
     if (empty($files) && !empty($wpdb->last_error)) {
         wp_die("<b>Database error</b>: " . $wpdb->last_error);
     }
     $this->items = $files;
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $filesperpage, 'total_pages' => ceil($total_items / $filesperpage)));
 }
コード例 #4
0
 function DBSave()
 {
     global $wpdb;
     if ($this->locked > 0) {
         $this->TriggerLockedError();
         return array('error' => 'Item locked.');
     }
     $values = array();
     $id_var = $this->is_file ? 'file_id' : 'cat_id';
     $vars = get_class_vars(get_class($this));
     foreach ($vars as $var => $def) {
         $pos = strpos($var, $this->is_file ? 'file_' : 'cat_');
         if ($pos === false || $pos != 0 || $var == $id_var || is_array($this->{$var}) || is_object($this->{$var})) {
             continue;
         }
         $values[$var] = $this->{$var};
         // no & ref here, this causes esc of actual objects data!!!!
     }
     if ($this->is_file) {
         $cvars = WPFB_Core::GetCustomFields(true);
         foreach ($cvars as $var => $cn) {
             $values[$var] = empty($this->{$var}) ? '' : $this->{$var};
         }
     }
     $update = !empty($this->{$id_var});
     $tbl = $this->is_file ? $wpdb->wpfilebase_files : $wpdb->wpfilebase_cats;
     if ($update) {
         if (!$wpdb->update($tbl, $values, array($id_var => $this->{$id_var}))) {
             if (!empty($wpdb->last_error)) {
                 return array('error' => 'Failed to update DB! ' . $wpdb->last_error);
             }
         }
     } else {
         if (!$wpdb->insert($tbl, $values)) {
             return array('error' => 'Unable to insert item into DB! ' . $wpdb->last_error);
         }
         $this->{$id_var} = (int) $wpdb->insert_id;
     }
     return array('error' => false, $id_var => $this->{$id_var}, 'id' => $this->{$id_var});
 }
コード例 #5
0
 static function FileSortFields()
 {
     return array_merge(array('file_display_name' => __('Title', WPFB), 'file_name' => __('Name of the file', WPFB), 'file_version' => __('File version', WPFB), 'file_hits' => __('How many times this file has been downloaded.', WPFB), 'file_size' => __('Formatted file size', WPFB), 'file_date' => __('Formatted file date', WPFB), 'file_last_dl_time' => __('Time of the last download', WPFB), 'file_path' => __('Relative path of the file'), 'file_id' => __('File ID'), 'file_category_name' => __('Category Name', WPFB), 'file_category' => __('Category ID', WPFB), 'file_description' => __('Short description', WPFB), 'file_author' => __('Author', WPFB), 'file_license' => __('License', WPFB), 'file_post_id' => __('ID of the post/page this file belongs to', WPFB), 'file_added_by' => __('User Name of the owner', WPFB)), WPFB_Core::GetCustomFields(true));
 }
コード例 #6
0
ファイル: wpfb_form_file.php プロジェクト: parsonsc/dofe
			</div>
		</td>
		
		<th scope="row" valign="top"></th>
		<td><input type="checkbox" name="file_offline" id="file_offline" value="1" <?php 
    checked('1', $file->file_offline);
    ?>
/> <label for="file_offline"><?php 
    _e('Offline', WPFB);
    ?>
</label></td>
		
	</tr>
	<?php 
}
$custom_fields = WPFB_Core::GetCustomFields(false, $custom_defaults);
foreach ($custom_fields as $ct => $cn) {
    $hid = 'file_custom_' . esc_attr($ct);
    ?>
	<tr class="form-field">
		<th scope="row" valign="top"><label for="<?php 
    echo $hid;
    ?>
"><?php 
    echo esc_html($cn);
    ?>
</label></th>
		<td colspan="3"><textarea name="<?php 
    echo $hid;
    ?>
" id="<?php 
コード例 #7
0
ファイル: Admin.php プロジェクト: parsonsc/dofe
 public static function SyncCustomFields($remove = false)
 {
     global $wpdb;
     // only once per request!
     static $synced = false;
     if ($synced) {
         return array();
     }
     $synced = true;
     $messages = array();
     $cols = $wpdb->get_col("SHOW COLUMNS FROM {$wpdb->wpfilebase_files} LIKE 'file_custom_%'");
     $custom_fields = WPFB_Core::GetCustomFields();
     foreach ($custom_fields as $ct => $cn) {
         if (!in_array('file_custom_' . $ct, $cols)) {
             $messages[] = sprintf(__($wpdb->query("ALTER TABLE {$wpdb->wpfilebase_files} ADD `file_custom_" . esc_sql($ct) . "` TEXT NOT NULL") ? "Custom field '%s' added." : "Could not add custom field '%s'!", WPFB), $cn);
         }
     }
     if (!$remove) {
         foreach ($cols as $cf) {
             $ct = substr($cf, 12);
             // len(file_custom_)
             if (!isset($custom_fields[$ct])) {
                 $messages[] = sprintf(__($wpdb->query("ALTER TABLE {$wpdb->wpfilebase_files} DROP `{$cf}`") ? "Custom field '%s' removed!" : "Could not remove custom field '%s'!", WPFB), $ct);
             }
         }
     }
     return $messages;
 }