function DownloadsManager_DownloadsPage($content) { global $wpdb, $table_prefix, $iconsdir; if (!preg_match("|<!--download table-->|", $content)) { return $content; } $start = strpos($content, '<!--download table-->'); $before = substr($content, 0, $start); $after = substr($content, 21 + $start); $dmTemplate = 'wp-content/plugins/downloads-manager/page-download-template.tpl'; $handle = @fopen($dmTemplate, 'r'); if (!$handle) { return __('Error... Unable to load page template. Search page-download-template.tpl in your plugin folder!', 'downloads-manager'); } $dmTemplateContent = fread($handle, filesize($dmTemplate)); $content = ""; $cats = $wpdb->get_results("SELECT id, name FROM " . $table_prefix . "dm_category"); if (!empty($cats)) { foreach ($cats as $cat) { $rows = $wpdb->get_results("SELECT d.id,d.name,d.link,d.icon,d.category,d.description,d.date,d.clicks FROM " . $table_prefix . "dm_downloads d WHERE d.category='" . $cat->id . "'", ARRAY_A); if (!empty($rows)) { $content .= "<h2 style=\"border-bottom: 1px dotted #CCC\">" . $cat->name . "</h2>"; foreach ($rows as $row) { $row['icon'] = $iconsdir . '/' . $row['icon']; $row['date'] = date('d/m/Y', $row['date']); $row['size'] = FileSizeOf($row['link']); $row['url'] = get_bloginfo('siteurl') . '/?file_id=' . $row['id']; $dmTemplateContent = preg_replace('/\\{(t)([^}]*)}/e', __('\\2', 'downloads-manager'), $dmTemplateContent); $content .= preg_replace('/\\{([^}]*)}/e', '$row[\\1]', $dmTemplateContent); } } } } fclose($handle); $content = $before . $content . $after; return $content; }
<th scope="col" colspan="2"><?php _e('Actions', 'downloads-manager'); ?> </th> </tr> </thead> <tbody id="the-list"> <?php if (!empty($rows)) { foreach ($rows as $row) { $permission = $row['permissions'] == 'yes' ? '<img src="' . $plugin_url . '/img/unlock.gif" alt="unlock.gif">' : '<img src="' . $plugin_url . '/img/lock.png" alt="lock.png">'; echo " <tr>\n"; echo " <td><img src=\"" . $plugin_url . "/img/icons/" . $row['icon'] . "\" alt=\"" . $row['icon'] . "\"></td>\n"; echo " <td class=\"alternate\"><a href=\"javascript: void(0);\" title=\"" . __('Click me!', 'downloads-manager') . "\" onClick=\"javascript: get_dm_code(event, '" . $row['id'] . "');\">" . $row['id'] . "</a></td>\n"; echo " <td class=\"alternate\"><a href=\"" . $row['link'] . "\">" . stripslashes($row['name']) . "</a></td>\n"; echo " <td class=\"alternate\">" . FileSizeOf($row['link']) . "</td>\n"; echo " <td class=\"alternate\">" . stripslashes($row['catname']) . "</td>\n"; echo " <td class=\"alternate\">" . date('d/m/Y', $row['date']) . "</td>\n"; echo " <td class=\"alternate\">" . $permission . "</td>\n"; echo " <td class=\"alternate\">" . $row['clicks'] . "</td>\n"; echo " <td class=\"alternate\">" . dm_avarage($row['date'], $row['clicks']) . "</td>\n"; echo " <td class=\"alternate\"><a href=\"#delete\" onClick=\"RemoveDownload('" . $row['id'] . "', '" . $row['name'] . "', '" . basename($row['link']) . "', '" . $row['link'] . "');\" class=\"delete\">" . __('Delete', 'downloads-manager') . "</a></td>"; echo " <td class=\"alternate\"><a href=\"#edit\" onClick=\"EditDownload('" . $row['id'] . "', '" . $row['name'] . "', '" . $row['catname'] . "', '" . $row['icon'] . "', '" . $row['description'] . "', '" . $row['permissions'] . "', '" . $row['link'] . "', '" . date('d/m/Y', $row['date']) . "', '" . $row['clicks'] . "');\" class=\"edit\">" . __('Edit', 'downloads-manager') . "</a></td>\n"; echo " </tr>\n"; } } else { echo " <tr>\n"; echo " <td class=\"alternate\" colspan=\"10\" style=\"text-align: center;\">" . __('There are no downloads!', 'downloads-manager') . "</td>\n"; echo " <tr>\n"; } ?>