Пример #1
0
function find_cid(array $titles, $parent = 0, $offset = 0)
{
    $con = new DataBaseTable('content', true, DATACONF);
    $cq = $con->getData("title:`{$titles[$offset]}` pid:`= {$parent}`", array('cid', 'title'));
    $ci = $cq->fetch(PDO::FETCH_OBJ);
    $offset++;
    if (!empty($titles[$offset])) {
        return find_cid($titles, $ci->cid, $offset);
    } else {
        return $ci->cid;
    }
}
Пример #2
0
function save_note($action, $data)
{
    $nt = new DataBaseTable('notes', true, DATACONF);
    if ($action == 'edit' && !empty($_GET['nid'])) {
        $data['nid'] = $_GET['nid'];
        if ($nid = $nt->updateData($data)) {
            return $nid;
        } else {
            return false;
        }
    } elseif ($action != "remove") {
        if ($nid = $nt->putData($data)) {
            return $nid;
        } else {
            return false;
        }
    } else {
        if ($nid = $nt->deleteData($data)) {
            return $nid;
        } else {
            return false;
        }
    }
}
Пример #3
0
function list_projects(MCSession $curusr, $filter = null)
{
    $table = new DataBaseTable('content', true, DATACONF);
    $q = "pid:`= 0`";
    if (!empty($filter)) {
        $q .= " " . $filter;
    }
    $q = $table->getData($q, null, null, $curusr->items_per_page, $_GET['offset']);
    $cols = $curusr->items_per_page / $curusr->rows_per_page;
    if ($q instanceof PDOStatement) {
        $grid = con_list_to_grid($q);
        $list = "<div id=\"ConList\" class=\"grid grid-col-{$cols}\">\n";
    }
    if (empty($grid)) {
        if (empty($curusr) || $curusr->level >= 3) {
            $html = "<div class=\"alert alert-warning\">No Content Posted! Please <a href=\"" . SITEROOT . "/?modal=login\">login</a> and post some stuff!!</div>";
        } else {
            $html = "<div class=\"alert alert-warning\">No Content Posted! Please open the <a href=\"" . SITEROOT . "dash/?section=projects\" data-toggle=\"modal\" data-target=\"#AJAXModal\">project manager</a> to add new content!</div>";
        }
    } else {
        $html = $list;
    }
    return $html;
}
Пример #4
0
#!/usr/bin/php

<?php 
require dirname(__FILE__) . "/appcore/dataconnect/database.inc.php";
fwrite(STDOUT, "Welcome to the Web Comic Manager!\n\nHere you will be able to perform basic functions and data manipulation as if you were logged in as an administrator. Please note: this program may present a security risk. In highly secure production environments it is a good idea to remove this file.\n");
fwrite(STDOUT, "What would you like to do?\n");
fwrite(STDOUT, "1) Look up, view, or edit a user\n");
fwrite(STDOUT, "0) Erase ALL data!\n");
$select = fgets(STDIN);
switch ($select) {
    case 1:
        $table = new DataBaseTable('users');
        fwrite(STDOUT, "Search query (press enter to look up all users): ");
        $query = fgets(STDIN);
        $query = $table->getData($query);
        while ($row = $query->fetch(PDO::FETCH_OBJ)) {
            fwrite(STDOUT, $row->id . "|" . $row->name . "|" . $row->email . "\n");
        }
        fwrite(STDOUT, "Select a user's id: ");
        $id = trim(fgets(STDIN), "\n");
        if (!is_numeric($id)) {
            exit;
        } else {
            $query = $table->getData("id:'= {$id}'");
            $user = $query->fetch(PDO::FETCH_ASSOC);
            foreach ($user as $key => $value) {
                if ($key == 'password') {
                    $value = "****";
                }
                fwrite(STDOUT, $key . ": " . $value . "\n");
            }
Пример #5
0
                while ($row = $q->fetch(PDO::FETCH_ASSOC)) {
                    $projects .= con_to_html($row);
                    $c++;
                }
            }
            if ($c <= 0) {
                $body .= "<div class=\"alert alert-warning\">You have no projects! Would you like to <a href=\"//{$conf->base_uri}/dash/?section=put&type=project\" data-target=\"#this-modal\">add one</a>?</div>\n";
            } else {
                $body .= "<div id=\"List\" class=\"panel-group\">\n{$projects}\n</div>\n<span class=\"alert alert-info\">You have {$c} project(s). <a href=\"./dash.php?section=put&type=project\" data-target=\"#this-modal\">Add another</a>?</span> <a href=\"javascript:location.reload()\" class=\"right btn btn-info\">Reload Index</a>\n";
            }
    }
}
if (!empty($_GET['json'])) {
    header("Content-type:'text/json'");
    $return_arr['okay'] = $success;
    $return_arr['message'] = $message;
    echo json_encode($return_arr);
} elseif (!empty($_GET['section'] == "author-search")) {
    $udb = new DataBaseTable('users', true, DATACONF);
    $uq = $udb->getData("name:`%{$_GET['q']}%`");
    echo json_encode($uq->fetchALL(PDO::FETCH_ASSOC));
} else {
    echo <<<HTML
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button><h4 class="modal-title">{$title}</h4></div>
<div class="modal-body">
<script src="//{$conf->base_uri}/appcore/scripts/ajaxlinks.js" type="text/javascript"></script>
{$body}
</div>
HTML;
}
Пример #6
0
function put_defaults($admin, $guest, $settings)
{
    $settings_tbl = new DataBaseTable('settings', true, dirname(__FILE__) . '/dataconnect/connect.ini');
    $type_tbl = new DataBaseTable('types', true, dirname(__FILE__) . '/dataconnect/connect.ini');
    $user_tbl = new DataBaseTable('users', true, dirname(__FILE__) . '/dataconnect/connect.ini');
    //TODO add descriptions
    $sys_types[0] = array('name' => "Book");
    $sys_types[1] = array('name' => 'Volume');
    $sys_types[2] = array('name' => 'Episode/Act');
    $sys_types[3] = array('name' => 'Issue');
    foreach ($sys_types as $types) {
        $type_rows[] = $type_tbl->putData($types);
    }
    if ($admin['pass1'] == $admin['pass2']) {
        $okay = 0;
        $totrows = 0;
        foreach ($settings as $setting['key'] => $setting['value']) {
            if ($row = $settings_tbl->putData($setting)) {
                $okay++;
            }
            $totrows++;
        }
        foreach ($guest as $key => $value) {
            if ($key != 'name') {
                $admin[$key] = $value;
                $root[$key] = $value;
            }
        }
        if ($guest = $user_tbl->putData($guest)) {
            $okay++;
        }
        $totrows++;
        $admin['password'] = crypt($admin['pass2']);
        $admin['level'] = 1;
        $root['name'] = "root";
        $root['level'] = 1;
        if ($root = $user_tbl->putData($root) && ($admin = $user_tbl->putData($admin))) {
            $okay++;
        }
        $totrows++;
        if ($okay == $totrows) {
            return true;
        }
    }
}
Пример #7
0
    $path_parts = explode("/", trim($path, "/"));
    if ($path_parts[1] == 'save') {
        $attachment = 'download';
    }
    $type = $path_parts[2];
    if ($type != 'content') {
        $type = $type . "s";
    }
    $id = $path_parts[3];
    $format = $path_parts[4];
} else {
    foreach ($_GET as $var => $val) {
        ${$var} = $val;
    }
}
$db = new DataBaseTable($type, true, DATACONF);
$col = substr($type, 0, 1) . "id";
$q = $db->getData($col . ":`= {$id}`");
$data = $q->fetch(PDO::FETCH_OBJ, PDO::FETCH_ORI_FIRST);
if (!empty($data->file)) {
    header("Location: //{$conf->base_uri}/{$data->file}");
} elseif ($type == 'content') {
    $doc = $data->data;
} else {
    $doc = $data->{$path_parts}[2];
}
if (!empty($attachment) && $attachment == 'download') {
    $filename = storagename($data->title);
    switch ($format) {
        /*case 'word':
          header ("Content-Type: application/msword");
Пример #8
0
function con_list_to_grid($q, $showprivate = false)
{
    $art = new DataBaseTable('art', true, DATACONF);
    while ($row = $q->fetch(PDO::FETCH_ASSOC)) {
        if ($showprivate || con_is_public($row['cid'])) {
            $aq = $art->getData("cid:`= {$row['cid']}`", array('ttid', 'uri'));
            $arts = array();
            while ($cover = $aq->fetch(PDO::FETCH_ASSOC)) {
                $types = new DataBaseTable('types', true, DATACONF);
                $tq = $types->getData("ttid:`= {$cover['ttid']}`");
                $tinfo = $tq->fetch(PDO::FETCH_ASSOC);
                if ($tinfo['ctype'] == 'art') {
                    $arts[] = array('file' => $cover['uri'], 'type' => $tinfo['name']);
                }
            }
            $path = build_con_path($row['cid']);
            if (con_is_public($row['cid'])) {
                $access = "public";
                $href = SITEROOT . $path;
            } else {
                $access = "private";
                $href = SITEROOT . $path . "/?modal=private";
            }
            $list .= "<div id=\"{$row['cid']}\" class=\"proj {$access} grid-item\"><a href=\"{$href}\">\n";
            if ($arts[0]['type'] == "Front Cover") {
                $list .= "<figure class=\"figure\">\n<img src=\"" . SITEROOT . "{$arts[0]['file']}?type=image/png&w=350\" width=\"350\" class=\"proj-cover figure-img img-fluid img-round\" alt=\"[cover]\">\n<figcaption class=\"proj-title figure-caption text-center\">{$row['title']}</figcaption>\n</figure>\n";
            } else {
                $list .= "<h3 class=\"proj-title\">{$row['title']}</h3>\n<p class=\"proj-description\">{$row['data']}</p>\n";
            }
            $list .= "</a></div>\n";
            $c++;
        }
    }
    return $list;
}
Пример #9
0
function save_asset($action, $data)
{
    $con = new DataBaseTable('content', true, DATACONF);
    $tags = new MCTags();
    if (!empty($_GET['cid'])) {
        if (empty($data['tags'])) {
            $tags->delAllByCon($_GET['cid']);
        } else {
            $tarr = explode(",", $data['tags']);
            $tags->changeAssoc($_GET['cid'], $tarr);
        }
    }
    //file uploads should be handled elsewhere...
    if ($action == 'drop') {
        $tags->delAllByCon($_GET['cid']);
        if ($cid = $con->deleteData($data)) {
            return $cid . " dropped";
        } else {
            return $cid . "could not be removed!";
        }
    } elseif (!empty($_GET['cid'])) {
        $data['cid'] = $_GET['cid'];
        if ($cid = $con->updateData($data)) {
            return $cid;
        } else {
            return false;
        }
    } else {
        if ($cid = $con->putData($data)) {
            return $cid;
        } else {
            return false;
        }
    }
}
Пример #10
0
function add_art($action, $data, $site_settings)
{
    $raw = file_get_contents($site_settings->project_dir . "/" . $data['temp_name']);
    unlink($site_settings->project_dir . "/" . $data['temp_name']);
    $image = imagecreatefromstring($raw);
    //TODO crop and/or resize image base on ttid?
    $user = new DataBaseTable("users", true, DATACONF);
    $user = $user->getData("uid:`= {$data['uid']}`");
    $user = $user->fetch(PDO::FETCH_ASSOC);
    if (!is_dir($site_settings->project_dir . "/" . storagename($user['name']))) {
        mkdir($site_settings->project_dir . "/" . storagename($user['name']));
    }
    $file = storagename($user['name']) . "/" . storagename($data['title']) . ".png";
    $art = new DataBaseTable("art", true, DATACONF);
    if (imagepng($image, $site_settings->project_dir . "/" . $file, 9)) {
        $data['uri'] = $file;
        if ($aid = $art->putData($data)) {
            return $aid . " added successfully!";
        } else {
            return $aid . " could not be added!";
        }
    } else {
        return $data['temp_name'] . " could not be opened for processing!";
    }
}
Пример #11
0
function view_doc($type, $id)
{
    $table = new DataBaseTable($type . "s", true, DATACONF);
    $col = substr($type, 0, 1) . "id";
    $q = $table->getData($col . ":`= " . $id);
    $siteroot = SITEROOT;
    $doc = $q->fetch(PDO::FETCH_ASSOC);
    return <<<HTML
<h2>{$doc['title']}</h2>
<div class="left" style="width:1em"><a href="{$siteroot}save/{$type}/{$id}/html"><span class="glyphicon glyphicon-save" title="Download"></span></a> <a href="{$siteroot}print/{$type}/{$id}"><span class="glyphicon glyphicon-print" title="Print"></span></a></div>
<div id="DocViewer" class="page" style="width:95%">
{$doc['note']}
</div>
HTML;
}
Пример #12
0
function search_form($full = false)
{
    $siteroot = SITEROOT;
    $form = "<form action=\"" . SITEROOT . "search/\" method=\"get\">\n<div class=\"form-group\"><label for=\"query\">Text (in title or description)</label><input type=\"search\" class=\"form-control\" name=\"q\">\n</div>\n";
    if ($full == TRUE) {
        $tdb = new DataBaseTable('tags', true, DATACONF);
        $tq = $tdb->getData();
        while ($tag = $tq->fetch()) {
            $filters .= "<div class=\"grid-item\"><input id=\"t-{$tag['tid']}\" type=\"checkbox\" name=\"tags[]\" value=\"{$tag['tid']}\"> <label for=\"t-{$tag['tid']}\" class=\"tag tag-{$tag['type']}\">{$tag['name']}</label></div>\n";
        }
        $form .= <<<HTML
<script language="javascript">
\$(function(){
 \$("input#author").keyup(function(){
  \$.get('{$siteroot}dash/?section=author-search&q='+\$("input#author").val(),function(data){
   \$("#authors").html('');
   for(var i=0;i<data.length;i++){
    \$("#authors").append('<option value="'+data[i].name+'"></option>');
   }
  },'json');
 });
});
</script>
<div class="alert alert-info">Did you know you can perform most advanced searches with just the above textbox? It's true!</div>
<div class="form-group">
<label for="author">Author:</label><input type="text" list="authors" class="form-control" name="author" id="author">
<datalist id="authors">
</datalist>
</div>
<div class="form-group">
<label for="tags">Tags:</label>
<div id="tags" class="grid grid-col-4">
{$filters}
</div>
</div>
<div class="form-group">
<label for="cdate">Date Posted:</label>
<div class="input-group">
<span class="input-group-addon">Between</span>
<input type="date" id="cdate" class="form-control" name="date-created[min]">
<span class="input-group-addon">and</span>
<input type="date" class="form-control" name="date-created[max]">
</div>
</div>
<div class="form-group">
<label for="mdate">Date Modified:</label>
<div class="input-group">
<span class="input-group-addon">Between</span>
<input type="date" id="mdate" class="form-control" name="date-modified[min]">
<span class="input-group-addon">and</span>
<input type="date" id="mdate2" class="form-control" name="date-modified[max]">
</div>
</div>
<div class="form-group">
<label for="price-min">Price:</label>
<div class="input-group">
<span class="input-group-addon">Between</span>
<input type="number" id="price-min" class="form-control" placeholder="Min:" name="price[min]">
<span class="input-group-addon">and</span>
<input type="number" id="price-max" class="form-control" placeholder="Max:" name="price[max]">
</div>
</div>
HTML;
    }
    $form .= "<div class=\"center\">\n<button class=\"btn btn-primary\" type=submit\"><span class=\"glyphicon glyphicon-search\"></span> Search</button>\n</form>\n";
    return $form;
}