コード例 #1
0
ファイル: earnings_loader.php プロジェクト: junkings/techlog
$month = $options['m'];
$income = (double) $options['i'];
$expend = (double) $options['e'];
$image_id = (int) $options['a'];
$sql = 'select path from images where image_id = ' . $image_id;
$path = Repository::findPathFromImages(array('eq' => array('image_id' => $image_id)));
if ($path == false) {
    LogOpt::set('exception', 'image_not_exists');
    return false;
}
$article = new ArticleModel(array('title' => $month . '财报', 'updatetime' => 'now()', 'inserttime' => 'now()', 'draft' => '<div>' . PHP_EOL . '<!-- 图片大小:700*467 -->' . PHP_EOL . '</div>', 'category_id' => 6));
$article_id = Repository::persist($article);
if ($article_id == false) {
    LogOpt::set('exception', 'new_note_insert_into_article_error');
    return false;
}
LogOpt::set('info', 'new_note_insert_into_article_success', 'article_id', $article_id);
$infos = array();
$infos['article_id'] = $article_id;
$infos['image_id'] = $image_id;
$infos['month'] = $month;
$infos['income'] = $income;
$infos['expend'] = $expend;
$earnings = new EarningsModel(array('article_id' => $article_id, 'image_id' => $image_id, 'month' => $month, 'income' => $income, 'expend' => $expend, 'inserttime' => 'now()'));
$earnings_id = Repository::persist($earnings);
if ($earnings_id == false) {
    LogOpt::set('exception', 'new_earnings_insert_into_booknote_error');
    return false;
}
LogOpt::set('info', 'new_earnings_insert_into_booknote_success', 'earnings_id', $earnings_id);
コード例 #2
0
ファイル: LogOpt.php プロジェクト: aleafboat/techlog
 public static function init($con, $needecho = false)
 {
     self::$condition = strtoupper($con);
     self::$echo = $needecho;
 }
コード例 #3
0
ファイル: contents_loader.php プロジェクト: junkings/techlog
        }
        $image_path = trim($image_path);
        if (!file_exists(WEB_PATH . '/resource/' . $image_path)) {
            LogOpt::set('exception', '文中目标图片不存在', 'image_path', $image_path);
            return;
        }
        $image_id = Repository::findImageIdFromImages(array('eq' => array('path' => $image_path)));
        if ($image_id == false) {
            $full_path = WEB_PATH . '/resource/' . $image_path;
            $image_id = TechlogTools::load_image($full_path, 'article');
            if ($image_id == false) {
                LogOpt::set('exception', '添加图片到数据库失败', 'image_path', $image_path);
                return;
            }
            LogOpt::set('info', '添加图片到数据库成功', 'image_id', $image_id, 'image_path', $image_path);
            $image_ids[] = $image_id;
        }
    }
    $article = Repository::findOneFromArticle(array('eq' => array('article_id' => $article_id)));
    foreach ($infos as $key => $value) {
        $func = 'set_' . $key;
        $article->{$func}($value);
    }
    $ret = Repository::persist($article);
    if ($ret == false) {
        LogOpt::set('exception', 'article 更新失败', 'article_id', $article_id);
        return;
    }
    LogOpt::set('info', 'article 更新成功', 'article_id', $ret);
    unlink($draft_file);
}
コード例 #4
0
ファイル: revise_article.php プロジェクト: aleafboat/techlog
<?php

require_once __DIR__ . '/../app/register.php';
LogOpt::init('revise_article', true);
$options = getopt('i:');
if (!isset($options['i']) || !is_numeric($options['i'])) {
    echo 'usage: php revise_article.php -i article_id' . PHP_EOL;
    return;
}
$article = Repository::findOneFromArticle(array('eq' => array('article_id' => $options['i'])));
if ($article == false) {
    LogOpt::set('exception', 'cannot find the article', 'article_id', $options['i']);
    return;
}
$filename = DRAFT_PATH . '/draft' . $options['i'] . '.tpl';
file_put_contents($filename, $article->get_draft());
LogOpt::set('info', '已将文件加载至' . $filename, 'article_id', $options['i'], 'title', $article->get_title());
コード例 #5
0
ファイル: article_creater.php プロジェクト: aleafboat/techlog
    return;
}
foreach ($tags as $tag) {
    $tag = trim($tag);
    if ($tag == '') {
        continue;
    }
    $tag_id = Repository::findTagIdFromTags(array('eq' => array('tag_name' => $tag)));
    if ($tag_id == false) {
        $tag = new TagsModel(array('tag_name' => $tag, 'inserttime' => 'now()'));
        $tag_id = Repository::persist($tag);
        if ($tag_id == false) {
            LogOpt::set('exception', 'tag 添加失败');
            continue;
        }
    }
    $article_tag_relation = new ArticleTagRelationModel(array('article_id' => $article_id, 'tag_id' => $tag_id, 'inserttime' => 'now()'));
    try {
        $relation_id = Repository::persist($article_tag_relation);
    } catch (PDOException $e) {
        LogOpt::set('exception', 'article_tag_relation 已存在', 'article_id', $article_id, 'tag_id', $tag_id);
        $pdo = Repository::getInstance();
        $pdo->rollback();
        continue;
    }
    if ($relation_id == false) {
        LogOpt::set('exception', 'article_tag_relation 更新失败', 'article_id', $article_id, 'tag_id', $tag_id);
        continue;
    }
    LogOpt::set('info', 'article_tag_relation 更新成功', 'relation_id', $relation_id);
}
コード例 #6
0
ファイル: note_loader.php プロジェクト: junkings/techlog
}
$bookname = $options['b'];
$image_id = intval(trim($options['i']));
$descs = isset($options['d']) ? $options['d'] : null;
$image = Repository::findOneFromImages(array('eq' => array('image_id' => $image_id)));
if ($image == false) {
    LogOpt::set('exception', 'image not exists', 'image_id', $image_id);
    return false;
}
$article = new ArticleModel(array('title' => $bookname, 'updatetime' => 'now()', 'inserttime' => 'now()', 'category_id' => 2));
$article_id = Repository::persist($article);
if ($article_id == false) {
    LogOpt::set('exception', 'new_note_insert_into_article_error');
    return false;
}
LogOpt::set('info', 'new_note_insert_into_article_success', 'article_id', $article_id);
$infos = array();
$infos['index_article_id'] = $article_id;
$infos['image_id'] = $image_id;
$infos['updatetime'] = 'now()';
if ($descs != null) {
    $infos['descs'] = $descs;
}
$booknote = new BooknoteModel(array('index_article_id' => $article_id, 'image_id' => $image_id, 'updatetime' => 'now()', 'inserttime' => 'now()'));
$note_id = Repository::persist($booknote);
if ($note_id == false) {
    LogOpt::set('exception', 'new_note_insert_into_booknote_error');
    return false;
}
LogOpt::set('info', 'new_note_insert_into_booknote_success', 'note_id', $note_id);
コード例 #7
0
ファイル: mood_loader.php プロジェクト: aleafboat/techlog
    }
    $mood_id = Repository::persist($mood);
    if ($mood_id === false) {
        LogOpt::set('exception', 'mood add error');
        continue;
    }
    LogOpt::set('info', 'mood add success', 'mood_id', $mood_id);
} else {
    echo 'usage: you can also use by ----' . ' php mood_loader -c contents [-i inserttime] [-d mood_id]' . PHP_EOL;
    while (1) {
        echo '> ';
        $contents = fgets(STDIN);
        $contents = trim($contents);
        if (strtolower($contents) === 'quit') {
            break;
        }
        if ($contents != '' && $contents != null) {
            echo '确认添加至说说吗? Y/N [N]:';
            $sure = fgets(STDIN);
            if (trim($sure[0]) == 'Y' || trim($sure[0]) == 'y') {
                $mood = new MoodModel(array('contents' => $contents));
                $mood_id = Repository::persist($mood);
                if ($mood_id === false) {
                    LogOpt::set('exception', 'mood add error', 'contents', $contents);
                    continue;
                }
                LogOpt::set('info', 'mood add success', 'mood_id', $mood_id);
            }
        }
    }
}
コード例 #8
0
ファイル: diary_loader.php プロジェクト: aleafboat/techlog
    $image_id = Repository::findImageIdFromImages(array('eq' => array('path' => $image_path)));
    if ($image_id == false) {
        $full_path = WEB_PATH . '/resource/' . $image_path;
        $image_id = TechlogTools::load_image($full_path, 'article');
        if ($image_id == false) {
            LogOpt::set('exception', '添加图片到数据库失败', 'image_path', $image_path);
        }
        LogOpt::set('info', '添加图片到数据库成功', 'image_id', $image_id, 'image_path', $image_path);
        $image_ids[] = $image_id;
    }
}
$infos['title'] = date('Y-m-d H:i:s');
if (isset($options['t'])) {
    $infos['title'] = $options['t'] . ' -- ' . date('Y-m-d');
}
$infos['category_id'] = '5';
// 获取 index
$indexs = json_encode(TechlogTools::get_index($contents));
if ($indexs != null) {
    $infos['indexs'] = $indexs;
}
$infos['updatetime'] = 'now()';
$infos['inserttime'] = 'now()';
$article = new ArticleModel($infos);
$article_id = Repository::persist($article);
if ($article_id == false) {
    LogOpt::set('exception', 'article insert error');
    return;
}
LogOpt::set('info', '添加日志成功', 'article_id', $article_id, 'title', $infos['title']);
unlink($draft_file);