Example #1
0
function module_sheet()
{
    global $global, $smarty;
    $cat = get_global('cat');
    $page = get_global('page');
    $prefix = 'data/mod-sheet';
    if ($cat) {
        $prefix = $prefix . '/cat-' . $cat;
    }
    $url = S_SERVER_URL . '?/data/cat-' . $cat . '/page-' . $page . '/index.html';
    $str = file_get_contents($url);
    $result = json_decode(rawurldecode($str), true);
    if (is_array($result)) {
        $server_cat_list = $result['cat_list'];
        $sheet = $result['sheet'];
        for ($i = 0; $i < count($sheet); $i++) {
            $obj = new article();
            $obj->set_where("art_title = '" . $sheet[$i]['art_title'] . "'");
            if ($obj->get_count()) {
                $sheet[$i]['is_exist'] = 1;
            } else {
                $sheet[$i]['is_exist'] = 0;
            }
        }
        $smarty->assign('page_sum', $result['page_sum']);
        $smarty->assign('prefix', $prefix);
    } else {
        $server_cat_list = array();
        $sheet = array();
    }
    $smarty->assign('article', $sheet);
    $cat_list = get_local_cat();
    if (count($cat_list) < count($server_cat_list)) {
        for ($i = 0; $i < count($server_cat_list); $i++) {
            $flag = false;
            for ($j = 0; $j < count($cat_list); $j++) {
                if ($server_cat_list[$i]['cat_id'] == $cat_list[$j]['server_id']) {
                    $flag = true;
                    if ($server_cat_list[$i]['cat_name'] != $cat_list[$j]['server_name']) {
                        $val = $server_cat_list[$i]['cat_id'] . '|' . $server_cat_list[$i]['cat_name'] . '|' . $cat_list[$i]['channel_id'] . '|' . $cat_list[$i]['cat_id'];
                        $obj = new varia();
                        $obj->set_value('var_value', $val);
                        $obj->set_where('var_id = ' . $cat_list[$i]['varia_id']);
                        $obj->edit();
                    }
                    break;
                }
            }
            if (!$flag) {
                $val = $server_cat_list[$i]['cat_id'] . '|' . $server_cat_list[$i]['cat_name'] . '|0|0';
                $obj = new varia();
                $obj->set_value('var_name', 'data_cat');
                $obj->set_value('var_value', $val);
                $obj->add();
            }
        }
        $cat_list = get_local_cat();
    }
    $smarty->assign('cat_list', $cat_list);
}
Example #2
0
/**
 * Shortcut for app address.
 * @param  string $prop
 * @return Froq\App|Froq\App\?|null
 * @throws \Throwable
 */
function app(string $prop = '')
{
    $app = get_global('app');
    if (!$prop) {
        return $app;
    }
    if (!strpbrk($prop, '.->')) {
        return $app->{$prop};
    }
    // evil or tricky?
    eval('$return = $app->' . str_replace('.', '->', $prop) . ';');
    return $return;
}
Example #3
0
function module_tailor_sheet()
{
    global $global, $smarty;
    $obj = new varia();
    $obj->set_where("var_name = 'tailor_data_cat'");
    $list = $obj->get_list();
    if (count($list)) {
        for ($i = 0; $i < count($list); $i++) {
            $arr = explode('|', $list[$i]['var_value']);
            $cat_list[$i]['server_id'] = $arr[0];
            $cat_list[$i]['server_name'] = $arr[1];
        }
    } else {
        $cat_list = array();
    }
    $smarty->assign('cat_list', $cat_list);
    $data_username = rawurlencode(get_varia('data_username'));
    $data_password = rawurlencode(get_varia('data_password'));
    $cat = get_global('cat');
    $page = get_global('page');
    $prefix = 'data/mod-tailor_sheet';
    $page_sum = 1;
    $sheet = array();
    if ($cat) {
        $prefix = $prefix . '/cat-' . $cat;
    }
    $url = S_SERVER_URL . 'tailor.php?/tailor/cat-' . $cat . '/page-' . $page . '/data_username-' . $data_username . '/data_password-' . $data_password . '/index.html';
    $str = file_get_contents($url);
    $result = json_decode(rawurldecode($str), true);
    if (is_array($result)) {
        if ($result['error'] == 'no') {
            $sheet = $result['sheet'];
            for ($i = 0; $i < count($sheet); $i++) {
                $obj = new article();
                $obj->set_where("art_title = '" . $sheet[$i]['art_title'] . "'");
                if ($obj->get_count()) {
                    $sheet[$i]['is_exist'] = 1;
                } else {
                    $sheet[$i]['is_exist'] = 0;
                }
            }
            $page_sum = $result['page_sum'];
        }
    }
    $smarty->assign('page_sum', $page_sum);
    $smarty->assign('prefix', $prefix);
    $smarty->assign('article', $sheet);
}
Example #4
0
function set_more_global()
{
    global $global;
    $global['channel'] = get_global('channel', 'index');
    $global['cat'] = get_global('cat', 0);
    $global['page'] = get_global('page', 1);
    $global['id'] = get_global('id', 0);
    $global['original'] = $global['channel'];
    $global['channel_id'] = get_id('channel', 'cha_code', $global['channel']);
    if ($global['channel_id']) {
        $original_id = get_data('channel', $global['channel_id'], 'cha_original');
        if ($original_id) {
            $global['original'] = get_data('channel', $original_id, 'cha_code');
        }
    }
}
Example #5
0
function set_more_global()
{
    global $global;
    $global['admin_id'] = check_admin_login();
    $global['channel'] = get_global('channel', 'basic');
    $global['original'] = get_global('original', 'basic');
    $global['mod'] = get_global('mod', 'basic_info');
    $global['cat'] = get_global('cat', 0);
    $global['page'] = get_global('page', 1);
    $global['id'] = get_global('id', 0);
    $global['original'] = $global['channel'];
    $global['channel_id'] = get_id('channel', 'cha_code', $global['channel']);
    if ($global['channel_id']) {
        $original_id = get_data('channel', $global['channel_id'], 'cha_original');
        if ($original_id) {
            $global['original'] = get_data('channel', $original_id, 'cha_code');
        }
    }
}
Example #6
0
 /**
  * Shutdown handler.
  *
  * @return void
  */
 public static final function handler()
 {
     return function () {
         $error = error_get_last();
         if (isset($error['type']) && $error['type'] == E_ERROR) {
             // pre($error);
             $error = sprintf('Shutdown! E_ERROR in %s:%d ecode[%d] emesg[%s]', $error['file'], $error['line'], $error['type'], $error['message']);
             // easy boy!
             $app = app();
             $app->logger->logFail($error);
             // handle response properly
             $app->response->setStatus(500);
             $app->response->setContentType('none');
             $app->response->send();
             // reset error display option
             $opt = get_global('display_errors');
             if ($opt !== null) {
                 ini_set('display_errors', $opt);
             }
         }
     };
 }
Example #7
0
 /**
  * Set body.
  *
  * @param  mixed $body
  * @return self
  */
 public final function setBody($body) : self
 {
     switch ($this->contentType) {
         // handle xml @todo
         case ContentType::XML:
             break;
             // handle json
         // handle json
         case ContentType::JSON:
             $json = new Json($body);
             // simply check for pretty print
             $app = app();
             if (is_in($app->request->params->get['pp'], ['1', 'true'])) {
                 $body = $json->encode(JSON_PRETTY_PRINT);
             } else {
                 $body = $json->encode();
             }
             if ($json->hasError()) {
                 throw new JsonException($json->getErrorMessage(), $json->getErrorCode());
             }
             break;
             // handle html
         // handle html
         case ContentType::HTML:
             // check for page title
             if ($pageTitle = get_global('page.title')) {
                 $body = preg_replace('~<title>(.*?)</title>~s', '<title>' . html_encode($pageTitle) . '</title>', $body, 1);
             }
             // check page description
             if ($pageDescription = get_global('page.description')) {
                 $body = preg_replace('~<meta\\s+name="description"\\s+content="(.*?)">~', '<meta\\s+name="description"\\s+content="' . html_encode($pageDescription) . '">', $body, 1);
             }
             break;
     }
     // can gzip?
     if (!empty($this->gzipOptions)) {
         $this->gzip->setData($body);
         if ($this->gzip->isDataMinlenOK()) {
             $body = $this->gzip->encode();
             $this->setHeader('Vary', 'Accept-Encoding');
             $this->setHeader('Content-Encoding', 'gzip');
         }
     }
     // content length
     $this->setContentLength(strlen($body));
     $this->body = $body;
     return $this;
 }
Example #8
0
function module_article_main()
{
    global $global, $smarty;
    if (!$global['id']) {
        $art_best = get_global('best');
        $prefix = get_data('channel', $global['channel_id'], 'cha_code');
        $list_len = get_varia('art_list_len');
        $obj = new article();
        $obj->set_where('art_channel_id = ' . $global['channel_id']);
        if ($global['cat']) {
            $family = implode(',', get_cat_family('cat_art', $global['cat']));
            $obj->set_where("art_cat_id in ({$family})");
            $prefix .= '/cat-' . $global['cat'];
        }
        if ($art_best) {
            $obj->set_where('art_best = 1');
            $prefix .= '/best-1';
        }
        $obj->set_page_size($list_len ? $list_len : 20);
        $obj->set_page_num($global['page']);
        $sheet = $obj->get_sheet();
        for ($i = 0; $i < count($sheet); $i++) {
            $sheet[$i]['short_title'] = cut_str($sheet[$i]['art_title'], 42);
        }
        set_link($obj->get_page_sum());
        $smarty->assign('show_sheet', 1);
        $smarty->assign('article', $sheet);
        $smarty->assign('prefix', $prefix);
    } else {
        $obj = new article();
        $obj->set_field('art_id,art_title,art_author,art_add_time,art_text');
        $obj->set_where('art_channel_id = ' . $global['channel_id']);
        $obj->set_where('art_id = ' . $global['id']);
        $one = $obj->get_one();
        $smarty->assign('article', $one);
        $obj = new article();
        $obj->set_field('art_id,art_title');
        $obj->set_where('art_channel_id = ' . $global['channel_id']);
        $obj->set_where('art_id < ' . $global['id']);
        $one = $obj->get_one();
        if (count($one)) {
            $smarty->assign('next_id', $one['art_id']);
            $smarty->assign('next_title', cut_str($one['art_title'], 15));
        } else {
            $smarty->assign('next_id', '');
            $smarty->assign('next_title', '');
        }
        $obj = new article();
        $obj->set_field('art_id,art_title');
        $obj->set_where('art_channel_id = ' . $global['channel_id']);
        $obj->set_where('art_id > ' . $global['id']);
        $obj->set_order('');
        $obj->set_order('art_top', 'asc');
        $obj->set_order('art_index', 'asc');
        $obj->set_order('art_id', 'asc');
        $one = $obj->get_one();
        if (count($one)) {
            $smarty->assign('prev_id', $one['art_id']);
            $smarty->assign('prev_title', cut_str($one['art_title'], 15));
        } else {
            $smarty->assign('prev_id', '');
            $smarty->assign('prev_title', '');
        }
        $obj = new varia();
        $smarty->assign('share_code', im_filter($obj->get_value('share_code', true)));
        $smarty->assign('show_sheet', 0);
    }
}
Example #9
0
 * 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. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
declare (strict_types=1);
/**
 * Shutdown handler.
 * @return callable
 */
return function () {
    $error = error_get_last();
    if (isset($error['type']) && $error['type'] == E_ERROR) {
        $error = sprintf('Shutdown! E_ERROR in %s:%d ecode[%d] emesg[%s]', $error['file'], $error['line'], $error['type'], $error['message']);
        // easy boy!
        $app = app();
        $app->logger->logFail($error);
        // handle response properly
        $app->response->setStatus(500);
        $app->response->setContentType('none');
        $app->response->send();
        // reset error display option (@see exception handler)
        $opt = get_global('app.displayErrors');
        if ($opt !== null) {
            ini_set('display_errors', $opt);
        }
    }
};
function get_payperiod_length()
{
    return get_global('pplength');
}
Example #11
0
/**
 * Shortcut for app address.
 * @return \Application\Application|mixed
 */
function app(string $prop = null)
{
    $app = get_global('app');
    return $prop ? $app->{$prop} : $app;
}
Example #12
0
 function settings_has_db_info()
 {
     $settings = get_global('settings');
     if (!is_array($settings)) {
         return FALSE;
     }
     $has = TRUE;
     foreach (['db_driver', 'db_host', 'db_name', 'db_user'] as $k) {
         if (!array_key_exists($k, $settings)) {
             $has = FALSE;
             break;
         }
     }
     return $has;
 }
        echo "<h3>{$msg}</h3>";
    } else {
        html_head();
        echo "<h3>{$msg}</h3>\n\n";
        html_tail();
        exit;
    }
}
// ---------------------------------------------------------------------------------------
// Get coordinates for east and west of 30W
// ---------------------------------------------------------------------------------------
if ($djia_e) {
    list($lat_e, $lon_e) = get_coords($get_date, $djia_e, $get_debug);
}
if ($djia_e) {
    list($lat_g, $lon_g) = get_global($get_date, $djia_e, $get_debug);
}
if ($djia_w) {
    list($lat_w, $lon_w) = get_coords($get_date, $djia_w, $get_debug);
}
// ---------------------------------------------------------------------------------------
if ($get_debug) {
    echo "<p>";
    if ($djia_e) {
        echo "\$lat_e = {$lat_e} \$lon_e = {$lon_e}";
    }
    if ($djia_w) {
        echo "<br>\$lat_w = {$lat_w} \$lon_w = {$lon_w}<br><br>\$lat_g = {$lat_g} \$lon_g = {$lon_g}";
    }
    echo "</p>\n\n";
}