Example #1
0
 public function listAction()
 {
     $notes = SqlRepository::getBooknotes();
     $booknotes = array();
     foreach ($notes as $note) {
         $infos = array();
         $infos['idx_href'] = '/article/list/' . $note->get_index_article_id();
         $infos['image_path'] = Repository::findPathFromImages(array('eq' => array('image_id' => $note->get_image_id())));
         $title = Repository::findTitleFromArticle(array('eq' => array('article_id' => $note->get_index_article_id())));
         $infos['title'] = mb_substr($title, 0, 35);
         $infos['descs'] = mb_substr($note->get_descs(), 0, 35);
         $booknotes[] = $infos;
     }
     $params = array('infos' => $booknotes, 'title' => '读书笔记', 'category_id' => 2);
     $this->display(__METHOD__, $params);
 }
Example #2
0
 public function listAction()
 {
     if (!$this->is_root) {
         header("Location: /index/notfound");
         return;
     }
     $det_beg = empty($_GET['beg']) ? date('Y-m', time()) : $_GET['beg'];
     $det_end = empty($_GET['end']) ? '2013-09' : $_GET['end'];
     if ($det_beg > $det_end) {
         list($det_beg, $det_end) = array($det_end, $det_beg);
     }
     $drw_beg = empty($_GET['drw_beg']) ? date('Y-m', time()) : $_GET['drw_beg'];
     $drw_end = empty($_GET['drw_end']) ? '2013-09' : $_GET['drw_end'];
     if ($drw_beg > $drw_end) {
         list($drw_beg, $drw_end) = array($drw_end, $drw_beg);
     }
     $query = 'select * from earnings order by month desc limit 24';
     $earnings = Repository::findFromEarnings(array('order' => array('month' => 'desc'), 'range' => array(0, 24)));
     $earn_infos = array();
     $month = array();
     $income = array();
     $expend = array();
     $index = 0;
     foreach ($earnings as $earning) {
         $infos = array();
         if ($earning->get_month() >= $det_beg and $earning->get_month() <= $det_end and $index < 12) {
             $infos['idx_href'] = '/article/list/' . $earning->get_article_id();
             $path = Repository::findPathFromImages(array('eq' => array('image_id' => $earning->get_image_id())));
             $infos['image_path'] = $path;
             $infos['title'] = $earning->get_month();
             $infos['descs'] = '结余:&nbsp;&nbsp;' . ($earning->get_income() - $earning->get_expend());
             $earn_infos[] = $infos;
             $index++;
         }
         if ($earning->get_month() >= $drw_beg and $earning->get_month() <= $drw_end) {
             $month[] = $earning->get_month();
             $income[] = $earning->get_income();
             $expend[] = $earning->get_expend();
         }
     }
     $average = round((array_sum($income) - array_sum($expend)) / count($month), 2);
     $params = array('det_beg_month' => $det_beg, 'det_end_month' => $det_end, 'drw_beg_month' => $drw_beg, 'drw_end_month' => $drw_end, 'labels' => json_encode(array_reverse($month)), 'income' => json_encode(array_reverse($income)), 'expend' => json_encode(array_reverse($expend)), 'average' => $average, 'infos' => $earn_infos, 'category_id' => 1, 'title' => '龙潭财报');
     $this->display('NoteController::listAction', $params);
 }
Example #3
0
<?php

require_once __DIR__ . '/../app/register.php';
LogOpt::init('earnings_loader', true);
$options = getopt('m:a:i:e:');
if (!isset($options['m']) || !isset($options['a']) || !isset($options['i']) || !isset($options['e'])) {
    echo "useage: php earnings_loader.php -m month -a image_id" . " -i income -e expend (图片大小:400*345)" . PHP_EOL;
    return;
}
$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;
Example #4
0
 public static function pre_treat_article($file)
 {
     $font = '';
     $lines = explode(PHP_EOL, $file);
     $contents = '';
     $code_id = 'a';
     $codes = array();
     for ($index = 0; $index < count($lines); ++$index) {
         $line = $lines[$index];
         $line = trim($line);
         if (empty($line)) {
             $contents .= '<p>&nbsp;</p>';
         } else {
             if ($line == '<div>') {
                 while (1) {
                     $index++;
                     if ($index >= count($lines)) {
                         break;
                     }
                     $line = trim($lines[$index]);
                     if ($line == '</div>') {
                         break;
                     }
                     $contents .= $line . PHP_EOL;
                 }
             } else {
                 if ($line == '<table>') {
                     $contents .= '<table class="stdtable" border="1" style="font-size:18;">';
                     while (1) {
                         $index++;
                         if ($index >= count($lines)) {
                             break;
                         }
                         $line = trim($lines[$index]);
                         if ($line == '</table>') {
                             $contents .= $line;
                             break;
                         } else {
                             if (substr($line, 0, 9) == '<caption>') {
                                 $caption = substr($line, 9);
                                 $contents .= '<caption' . ' style=\'font-weight:bold;' . ' font-family:"PT Serif","Georgia","Helvetica Neue",Arial,sans-serif;' . ' background-color:#D2E1F0; height:30px;\'>' . $caption . '</caption>';
                             } else {
                                 $tds = explode("\t", $line);
                                 if (substr($line, 0, 4) == '<tr>') {
                                     $tds[0] = substr($tds[0], 4);
                                     $contents .= '<thead>' . '<tr style="background-color:#C5C5C5;">';
                                     if ($tds[0][0] == '[' && $tds[0][strlen($tds[0]) - 1] == ']') {
                                         $widths = substr($tds[0], 1, strlen($tds[0]) - 2);
                                         $widths = explode(":", $widths);
                                         for ($i = 1; $i < count($tds); ++$i) {
                                             if (isset($widths[$i - 1])) {
                                                 $contents .= '<td width="' . $widths[$i - 1] . '%"><strong>' . $tds[$i] . '</strong></td>';
                                             } else {
                                                 $contents .= '<td><strong>' . $tds[$i] . '</strong></td>';
                                             }
                                         }
                                     } else {
                                         $contents .= '<td><strong>' . implode('</strong></td><td><strong>', $tds) . '</strong></td>';
                                     }
                                     $contents .= '</tr></thead>';
                                 } else {
                                     $tmp_tds = array();
                                     foreach ($tds as $td) {
                                         if ($td !== '') {
                                             $tmp_tds[] = $td;
                                         }
                                     }
                                     $contents .= '<tr><td>' . implode('</td><td>', $tmp_tds) . '</td></tr>';
                                 }
                             }
                         }
                     }
                 } else {
                     if ($line == '<ol>' || $line == '<ul>') {
                         $contents .= $line;
                         while (1) {
                             $index++;
                             if ($index >= count($lines)) {
                                 break;
                             }
                             $line = trim($lines[$index]);
                             if ($line == '</ol>' || $line == '</ul>') {
                                 $contents .= $line;
                                 break;
                             } else {
                                 $line = self::str_trans($line);
                                 if ($font != '') {
                                     $line = '<span style="font-family:' . $font . ';">' . $line . '</span>';
                                 }
                                 $contents .= '<p><li>' . $line . '</li></p>';
                             }
                         }
                     } else {
                         if (substr($line, 0, 5) == '<font') {
                             $font = StringOpt::spider_string($line, '<font ', '>');
                         } else {
                             if ($line == '</font>') {
                                 $font = '';
                             } else {
                                 if (substr($line, 0, 4) == '<img') {
                                     $id = StringOpt::spider_string($line, 'id="', '"');
                                     if ($id != null) {
                                         $image_id = intval(trim($id));
                                         $path = Repository::findPathFromImages(array('eq' => array('image_id' => $image_id)));
                                         if ($path != false) {
                                             $line = str_replace('id="' . $id . '"', 'src="' . $path . '"', $line);
                                         } else {
                                             $line = '<strong>图片ID不存在</strong>';
                                         }
                                     } else {
                                         $path = StringOpt::spider_string($line, 'src="', '"');
                                     }
                                     $image_info = GetImageSize(WEB_PATH . '/resource/' . $path);
                                     $image_info = $image_info['3'];
                                     $width = StringOpt::spider_string($image_info, 'width="', '"');
                                     $width = intval(trim($width));
                                     $contents .= '<p style="text-indent:0em;">' . '<a target="_blank" alt="' . $width . '" href="' . $path . '">' . $line . '</a></p><p>&nbsp;</p>';
                                 } else {
                                     if (substr($line, 0, 5) == '<code') {
                                         $mode = StringOpt::spider_string($line, 'mode="', '"');
                                         if (empty($mode)) {
                                             $mode = 'c_cpp';
                                         }
                                         $code = '';
                                         $code_line = 0;
                                         $is_php = false;
                                         if ($mode === 'php' && $lines[$index + 1] != '<?php') {
                                             $is_php = true;
                                         }
                                         while (1) {
                                             $index++;
                                             if ($index >= count($lines)) {
                                                 break;
                                             }
                                             $line = $lines[$index];
                                             if (trim($line) === '</code>') {
                                                 break;
                                             }
                                             $code_wrap = 0;
                                             for ($idx = 0; $idx < strlen($line); ++$idx) {
                                                 if ($line[$idx] == "\t") {
                                                     $code_wrap += 4;
                                                     continue;
                                                 }
                                                 $value = ord($line[$idx]);
                                                 if ($value > 127) {
                                                     $code_wrap++;
                                                     if ($value >= 192 && $value <= 223) {
                                                         $idx++;
                                                     } elseif ($value >= 224 && $value <= 239) {
                                                         $idx = $idx + 2;
                                                     } elseif ($value >= 240 && $value <= 247) {
                                                         $idx = $idx + 3;
                                                     }
                                                 }
                                                 $code_wrap++;
                                             }
                                             $code_line += floor($code_wrap / 80) + 1;
                                             $code .= self::str_trans($line, false) . PHP_EOL;
                                         }
                                         if ($is_php) {
                                             $code = '&lt;?php' . PHP_EOL . $code . '?&gt;';
                                             $code_line += 2;
                                         }
                                         if ($code_line > 30) {
                                             $code_line = 30;
                                         }
                                         $contents .= '<div id="editor_' . $code_id . '"' . ' style="position: relative;' . ' width: 765px;' . ' height: ' . $code_line . 'px">' . trim($code) . '</div><p>&nbsp;</p>';
                                         $codes[] = array('id' => 'editor_' . $code_id++, 'mode' => $mode);
                                         continue;
                                     } else {
                                         if (substr($line, 0, 4) === '<h1>') {
                                             $contents .= '<div class="page-header"><h1 id="' . $code_id++ . '">' . self::str_trans(substr($line, 4)) . '</h1></div>';
                                         } else {
                                             if (substr($line, 0, 4) === '<h3>') {
                                                 $contents .= '<p><h3>' . self::str_trans(substr($line, 4)) . '</h3></p>';
                                             } else {
                                                 if (substr($line, 0, 2) == '<a') {
                                                     $id = StringOpt::spider_string($line, 'id="', '"');
                                                     $title = Repository::findTitleFromArticle(array('eq' => array('article_id' => $id)));
                                                     if (!$title) {
                                                         $title = 'ERROR:加载失败';
                                                     }
                                                     $contents .= '<p><a target="_blank" href="/article/list/' . $id . '">' . $title . '</a></p>';
                                                 } else {
                                                     $line = self::str_trans($line);
                                                     if ($font != '') {
                                                         $line = '<span style="font-family:' . $font . ';">' . $line . '</span>';
                                                     }
                                                     $contents .= '<p>' . $line . '</p>';
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if (!empty($codes)) {
         $js_arr = array();
         foreach ($codes as $code) {
             $js_arr[] = '{"id":"' . $code['id'] . '","mode":"' . $code['mode'] . '"}';
         }
         $contents .= '<script>var CODE_DIVS=[';
         $contents .= implode(',', $js_arr);
         $contents .= '];</script>';
     }
     return $contents;
 }