Skip to content

Commit

Permalink
initial add
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkingorg committed Feb 15, 2011
0 parents commit fb9f0a0
Show file tree
Hide file tree
Showing 18 changed files with 1,104 additions and 0 deletions.
87 changes: 87 additions & 0 deletions backend/functions.inc.php
@@ -0,0 +1,87 @@
<?php

// iTunes Stats
//
// Copyright (c) 2005-2010 Alex King. All rights reserved.
// http://alexking.org
//
// Released under the GPL license
// http://www.opensource.org/licenses/gpl-license.php
//
// **********************************************************************
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// **********************************************************************

function print_pre($data) {
print('<pre>');
print_r($data);
print('</pre>');
}

function get_reports() {
$reports = array();

$report_meta = array(
'name' => 'Report Name:'
, 'description' => 'Description:'
, 'URL' => 'Report URL:'
, 'version' => 'Version:'
, 'author' => 'Author:'
, 'author_URL' => 'Author URL:'
, 'category' => 'Category:'
);

$path = 'reports/';
if ($handle = opendir($path)) {
while (false !== ($filename = readdir($handle))) {
if ($filename != "." && $filename != ".." && is_file($path.$filename) &&
strtolower(substr($filename, -4, 4)) == ".php") {
$data = file($path.$filename);
$report = new report;
for ($i = 0; $i < count($data); $i++) {
$report->key = str_replace(array('.inc.php', '.php'), '', $filename);
foreach ($report_meta as $property => $string) {
if (strstr($data[$i], $string)) {
$report->$property = trim(str_replace($string, '', $data[$i]));
}
}
if (strstr($data[$i], '*/')) {
if (!empty($report->category)) {
if (!isset($reports[$report->category])) {
$reports[$report->category] = array();
}
$reports[$report->category][] = $report;
}
else {
$reports[] = $report;
}
$i = count($data);
}
}
}
}
closedir($handle);
}

return $reports;
}

function print_reports_category($title = '', $reports = array()) {
if (count($reports) < 1) {
return;
}
print('
<h3 class="reports">'.$title.'</h3>
<dl class="reports">
');
foreach ($reports as $report) {
$report->print_dl_item();
}
print('
</dl>
');
}

?>
264 changes: 264 additions & 0 deletions backend/objects.inc.php
@@ -0,0 +1,264 @@
<?php

// iTunes Stats
//
// Copyright (c) 2005-2010 Alex King. All rights reserved.
// http://alexking.org
//
// Released under the GPL license
// http://www.opensource.org/licenses/gpl-license.php
//
// **********************************************************************
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// **********************************************************************

class artist {
var $id;
var $name;
var $albums;
var $songs;

function insert() {
global $database_table_prefix;

mysql_query("
INSERT
INTO `".$database_table_prefix."artist`
( `name`
)
VALUES
( '".addslashes($this->name)."'
)
") or die(mysql_error());

$this->id = mysql_insert_id();
}
}

class album {
var $id;
var $name;
var $artist;
var $artist_id;
var $songs;
var $rating;

function insert() {
global $database_table_prefix;

mysql_query("
INSERT
INTO `".$database_table_prefix."album`
( `name`
, `artist`
)
VALUES
( '".addslashes($this->name)."'
, '".addslashes($this->artist)."'
)
") or die(mysql_error());

$this->id = mysql_insert_id();
}
}

class song {
var $id;
var $name;
var $artist;
var $artist_id;
var $album;
var $album_id;
var $play_count;
var $rating;

function song() {
$this->artist_id = 0;
$this->album_id = 0;
$this->play_count = 0;
$this->rating = 0;
}

function insert() {
global $database_table_prefix;

if (!empty($this->artist)) {
$result = mysql_query("
SELECT *
FROM `".$database_table_prefix."artist`
WHERE `name` = '".addslashes($this->artist)."'
") or die(mysql_error());

if (mysql_num_rows($result) == 0) {
$artist = new artist;
$artist->name = $this->artist;
$artist->insert();
$this->artist_id = $artist->id;
}
else {
while ($data = mysql_fetch_object($result)) {
$this->artist_id = $data->id;
}
}
}

if (!empty($this->album)) {
$result = mysql_query("
SELECT *
FROM `".$database_table_prefix."album`
WHERE `name` = '".addslashes($this->album)."'
AND `artist` = '".addslashes($this->artist_id)."'
") or die(mysql_error());

if (mysql_num_rows($result) == 0) {
$album = new album;
$album->name = $this->album;
$album->artist = $this->artist_id;
$album->insert();
$this->album_id = $album->id;
}
else {
while ($data = mysql_fetch_object($result)) {
$this->album_id = $data->id;
}
}
}

$result = mysql_query("
INSERT
INTO `".$database_table_prefix."song`
( `name`
, `rating`
, `play_count`
, `artist`
, `album`
)
VALUES
( '".addslashes($this->name)."'
, '".addslashes($this->rating)."'
, '".addslashes($this->play_count)."'
, '".addslashes($this->artist_id)."'
, '".addslashes($this->album_id)."'
)
") or die(mysql_error());

$this->id = mysql_insert_id();
}
}

class grid {
var $items;
var $columns;

function grid() {
$this->items = array();
$this->columns = array();
}

function display() {
print('
<table class="report" cellspacing="1">
<thead>
<tr>
<th></th>
');
foreach ($this->columns as $title => $property) {
print('
<th>'.$title.'</th>
');
}
print('
</tr>
</thead>
<tbody>
');
$i = 0;
foreach ($this->items as $item) {
$i++;
if ($i % 2 != 0) {
$class = ' class="odd"';
}
else {
$class = '';
}
print('
<tr'.$class.'>
<td class="right">'.$i.'</td>
');
foreach ($this->columns as $title => $property) {
if (!in_array($title, array('Artist', 'Album', 'Song'))) {
$class = ' class="right"';
}
else {
$class = '';
}
print('
<td'.$class.'>'.$item->$property.'</td>
');
}
print('
</tr>
');
}
print('
</tbody>
</table>
');
}
}

class report {
var $author;
var $author_URL;
var $name;
var $description;
var $version;
var $URL;
var $key;
var $category;

function report() {
$this->author = '';
$this->author_URL = '';
$this->name = '';
$this->description = '';
$this->version = '';
$this->URL = '';
$this->key = '';
$this->category = '';
}

function author_link() {
if (empty($this->author) && empty($this->author_URL)) {
return 'Anonymous';
}
else if (!empty($this->author) && !empty($this->author_URL)) {
return '<a href="'.$this->author_URL.'">'.$this->author.'</a>';
}
else if (!empty($this->author) && empty($this->author_URL)) {
return $this->author;
}
else if (empty($this->author) && !empty($this->author_URL)) {
return '<a href="'.$this->author_URL.'">'.$this->author_URL.'</a>';
}
}

function print_dl_item() {
print('
<dt><a href="index.php?report='.$this->key.'">'.$this->name.'</a></dt>
<dd>
<p>'.$this->description.'</p>
<ul>
<li>Version: '.$this->version.'</li>
<li>By: '.$this->author_link().'</li>
</ul>
</dd>
');

}

}

?>
26 changes: 26 additions & 0 deletions config.inc.php
@@ -0,0 +1,26 @@
<?php

// iTunes Stats
//
// Copyright (c) 2005-2010 Alex King. All rights reserved.
// http://alexking.org
//
// Released under the GPL license
// http://www.opensource.org/licenses/gpl-license.php
//
// **********************************************************************
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// **********************************************************************

$database_host = 'localhost';
$database_name = 'itunes_stats';
$database_user = 'username';
$database_pass = 'password';

$database_table_prefix = 'its_'; // set this to whatever you like

$config_your_name = ''; // set this to your name, HTML is OK

?>
1 change: 1 addition & 0 deletions css/default.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added images/content_background.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/header_background.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fb9f0a0

Please sign in to comment.