Ejemplo n.º 1
0
<?php

$object = new WechatAccount();
// handle form submission
if (isset($_POST['submit'])) {
    $error_flag = false;
    /// validation
    // validation for $nickname
    $nickname = isset($_POST["nickname"]) ? strip_tags($_POST["nickname"]) : null;
    if (empty($nickname)) {
        Message::register(new Message(Message::DANGER, i18n(array("en" => "nickname is required.", "zh" => "请填写nickname"))));
        $error_flag = true;
    }
    // validation for $wechat_id
    $wechat_id = isset($_POST["wechat_id"]) ? strip_tags($_POST["wechat_id"]) : null;
    if (empty($wechat_id)) {
        Message::register(new Message(Message::DANGER, i18n(array("en" => "wechat_id is required.", "zh" => "请填写wechat_id"))));
        $error_flag = true;
    }
    // validation for $openid
    $openid = isset($_POST["openid"]) ? strip_tags($_POST["openid"]) : null;
    if (empty($openid)) {
        Message::register(new Message(Message::DANGER, i18n(array("en" => "openid is required.", "zh" => "请填写openid"))));
        $error_flag = true;
    }
    // validation for $introduction
    $introduction = isset($_POST["introduction"]) ? $_POST["introduction"] : null;
    // validation for $cirtification
    $cirtification = isset($_POST["cirtification"]) ? $_POST["cirtification"] : null;
    // validation for $qr_code
    $qr_code = isset($_POST["qr_code"]) ? strip_tags($_POST["qr_code"]) : null;
Ejemplo n.º 2
0
<?php

$page = isset($_GET['page']) ? $_GET['page'] : 1;
if (!preg_match('/^\\d+$/', $page)) {
    dispatch('core/backend/404');
    exit;
}
$objects = WechatAccount::findAll();
$html = new HTML();
$html->renderOut('core/backend/html_header', array('title' => i18n(array('en' => 'Wechat Account', 'zh' => '微信公共账号'))), true);
$html->output('<div id="wrapper">');
$html->renderOut('core/backend/header');
$perpage = 50;
$total = WechatAccount::countAll();
$total_page = ceil($total / $perpage);
$html->renderOut('wechat_account/backend/wechat_account_list', array('objects' => WechatAccount::findAllWithPage($page, $perpage), 'current_page' => $page, 'total_page' => $total_page, 'total' => $total, 'pager' => $html->render('core/components/pagination', array('total' => $total_page, 'page' => $page)), 'start_entry' => ($page - 1) * $perpage + 1, 'end_entry' => min(array($total, $page * $perpage))), true);
$html->output('</div>');
$html->renderOut('core/backend/html_footer');
exit;
$result_dir = CACHE_DIR . DS . 'phantomjs_results';
if ($handle = opendir($result_dir)) {
    $i = 0;
    while (false !== ($entry = readdir($handle))) {
        if (preg_match('/^account_craw/', $entry) && $i < $how_many_processed_once) {
            $file = $result_dir . DS . $entry;
            // get created date from file name
            $matches = array();
            preg_match('/_((\\d+)\\-\\d+\\-\\d+)\\-/', $file, $matches);
            $date = $matches[1];
            $year = $matches[2];
            // get wechat_id from file name
            $matches = array();
            preg_match('/account_crawl_([^_]+)_/', $file, $matches);
            $wechat_id = $matches[1];
            $wechat_account = WechatAccount::findByWechatId($wechat_id);
            if ($wechat_account == null) {
                $log = new Log('wechat_account', Log::ERROR, 'Collect error: can not find wechat_account with wechat_id:' . $wechat_id);
                unlink($file);
                exit;
            }
            // parse html
            load_library_simple_html_dom();
            $html = file_get_contents($file);
            unlink($file);
            if (strpos($html, '[Error]') !== FALSE) {
                $log = new Log('wechat_account', Log::ERROR, $html);
                $log->save();
            } else {
                $dom = str_get_html($html);
                foreach ($dom->find('.wx-rb3') as $article) {
<?php

/**
 * This script makes up shell scripts that calls phantomjs
 */
require __DIR__ . "/../../../bootstrap.php";
// prepare directories
$script_dir = CACHE_DIR . DS . 'phantomjs_scripts';
$result_dir = CACHE_DIR . DS . 'phantomjs_results';
if (!is_dir($script_dir)) {
    mkdir($script_dir);
}
if (!is_dir($result_dir)) {
    mkdir($result_dir);
}
// generates phantomjs scripts
$accounts = WechatAccount::findAllToCrawl(3500);
foreach ($accounts as $account) {
    // append Shanghai timestamp at the end of file name, so that when we collect
    // the file, we know when it was created
    $original_timezone = date_default_timezone_get();
    date_default_timezone_set('Asia/Shanghai');
    $filename = 'account_crawl_' . $account->getWechatId() . '_' . date('Y-m-d-H-i-s');
    date_default_timezone_set($original_timezone);
    $script_file = $script_dir . DS . $filename . '.sh';
    $result_file = $result_dir . DS . $filename;
    file_put_contents($script_file, 'phantomjs ' . MODULESROOT . '/wechat_account/phantomjs/articles.js "http://weixin.sogou.com/gzh?openid=' . $account->getOpenid() . '" > ' . $result_file);
    chmod($script_file, 0700);
    $account->setLastScheduled(time());
    $account->save();
}
Ejemplo n.º 5
0
<?php

$id = isset($vars[1]) ? $vars[1] : null;
$object = WechatAccount::findById($id);
if (is_null($object)) {
    HTML::forward('core/404');
}
// handle form submission
if (isset($_POST['submit'])) {
    $error_flag = false;
    /// validation
    // validation for $nickname
    $nickname = isset($_POST["nickname"]) ? strip_tags($_POST["nickname"]) : null;
    if (empty($nickname)) {
        Message::register(new Message(Message::DANGER, i18n(array("en" => "nickname is required.", "zh" => "请填写nickname"))));
        $error_flag = true;
    }
    // validation for $wechat_id
    $wechat_id = isset($_POST["wechat_id"]) ? strip_tags($_POST["wechat_id"]) : null;
    if (empty($wechat_id)) {
        Message::register(new Message(Message::DANGER, i18n(array("en" => "wechat_id is required.", "zh" => "请填写wechat_id"))));
        $error_flag = true;
    }
    // validation for $openid
    $openid = isset($_POST["openid"]) ? strip_tags($_POST["openid"]) : null;
    if (empty($openid)) {
        Message::register(new Message(Message::DANGER, i18n(array("en" => "openid is required.", "zh" => "请填写openid"))));
        $error_flag = true;
    }
    // validation for $introduction
    $introduction = isset($_POST["introduction"]) ? $_POST["introduction"] : null;
Ejemplo n.º 6
0
<?php

//-- WechatAccount:Clear cache
if ($command == "cc") {
    if ($arg1 == "all" || $arg1 == "wechat_account") {
        echo " - Drop table 'wechat_account' ";
        echo WechatAccount::dropTable() ? "success\n" : "fail\n";
    }
}
//-- WechatAccount:Import DB
if ($command == "import" && $arg1 == "db" && (is_null($arg2) || $arg2 == "wechat_account")) {
    //- create tables if not exits
    echo " - Create table 'wechat_account' ";
    echo WechatAccount::createTableIfNotExist() ? "success\n" : "fail\n";
}
//-- WechatArticle:Clear cache
if ($command == "cc") {
    if ($arg1 == "all" || $arg1 == "wechat_account") {
        echo " - Drop table 'wechat_article' ";
        echo WechatArticle::dropTable() ? "success\n" : "fail\n";
    }
}
//-- WechatArticle:Import DB
if ($command == "import" && $arg1 == "db" && (is_null($arg2) || $arg2 == "wechat_article")) {
    //- create tables if not exits
    echo " - Create table 'wechat_article' ";
    echo WechatArticle::createTableIfNotExist() ? "success\n" : "fail\n";
}
//-- WechatAccountUser:Clear cache
if ($command == "cc") {
    if ($arg1 == "all" || $arg1 == "wechat_account") {
Ejemplo n.º 7
0
 public function getWechatAccount()
 {
     return WechatAccount::findById($this->getAccountId());
 }
Ejemplo n.º 8
0
<?php

$response = new stdClass();
if (!has_permission('manager feeds')) {
    $response->status = 'error';
    $response->message = '您没有权限进行此操作';
    echo json_encode($response);
    exit;
}
$openid = isset($_POST['openid']) ? strip_tags($_POST['openid']) : null;
$wechat_account = WechatAccount::findByOpenid($openid);
// check if the account exists
if ($wechat_account == null) {
    $response->status = 'error';
    $response->message = '此公众号不存在,无法退订';
    echo json_encode($response);
    exit;
}
// check if the user has subscribed the account
$user_wechat_account = UserWechatAccount::findByWechatAccountId($wechat_account->getId());
if (!$user_wechat_account) {
    $response->status = 'error';
    $response->message = '您并没有订阅此公众号,无法退订';
    echo json_encode($response);
    exit;
}
// unsubscribe
if ($user_wechat_account->delete()) {
    $response->status = 'success';
} else {
    $response->status = 'error';
Ejemplo n.º 9
0
<div class="container" id="body">
<?php 
if ($articles) {
    foreach ($articles as $article) {
        $subscribed = false;
        if ($wechat_account = WechatAccount::findByOpenid($article['openid'])) {
            if (UserWechatAccount::findByWechatAccountId($wechat_account->getId())) {
                $subscribed = true;
            }
        }
        ?>
  <article class="row article">
    <div class="col-xs-12 content">
      <div class="inner">
        <div class="left">
          <img class="lazyloading" src="<?php 
        echo uri('modules/site/assets/images/ajax-loader-2.gif');
        ?>
" data-source="<?php 
        echo $article['thumb'];
        ?>
" />
        </div>
        <div class="middle">
          <?php 
        if (isset($article['title'])) {
            ?>
          <h2><?php 
            echo $article['title'];
            ?>
</h2>
Ejemplo n.º 10
0
 public function delete()
 {
     $rtn = parent::delete();
     // delete extra relationship for wechat_account_user if existed
     if ($rtn) {
         $user = MySiteUser::getCurrentUser();
         $wechat_account_user = WechatAccountUser::findbyCombo($this->getAccountId(), $user->getId());
         if ($wechat_account_user) {
             $wechat_account_user->delete();
         }
     }
     // check if there is any other users subscribing this wechat_account, if no, we delete it
     if ($rtn) {
         $wechat_account_users = WechatAccountUser::findByAccountId($this->getAccountId());
         if (sizeof($wechat_account_users) == 0) {
             $wechat_account = WechatAccount::findById($this->getAccountId());
             $wechat_account->delete();
         }
     }
     return $rtn;
 }
Ejemplo n.º 11
0
    $response->status = 'error';
    $response->message = '您没有权限进行此操作';
    echo json_encode($response);
    exit;
}
$openid = isset($_POST['openid']) ? strip_tags($_POST['openid']) : null;
$wechatid = isset($_POST['wechatid']) ? strip_tags($_POST['wechatid']) : null;
$description = isset($_POST['description']) ? strip_tags($_POST['description']) : null;
$certification = isset($_POST['certification']) ? strip_tags($_POST['certification']) : null;
$nickname = isset($_POST['nickname']) ? strip_tags($_POST['nickname']) : null;
$qrcode = isset($_POST['qrcode']) ? strip_tags($_POST['qrcode']) : null;
$logo = isset($_POST['logo']) ? strip_tags($_POST['logo']) : null;
// if wechat account hasn't been added globally, we add it
$wechat_account = WechatAccount::findByOpenid($openid);
if ($wechat_account == null) {
    $wechat_account = new WechatAccount();
    $wechat_account->setDescription($description);
    $wechat_account->setCertification($certification);
    $wechat_account->setOpenid($openid);
    $wechat_account->setWechatId($wechatid);
    $wechat_account->setLogo($logo);
    $wechat_account->setQrCode($qrcode);
    $wechat_account->setNickname($nickname);
    $wechat_account->save();
}
$user_wechat_account = UserWechatAccount::findByWechatAccountId($wechat_account->getId());
if ($user_wechat_account) {
    $response->status = 'error';
    $response->message = '此公众号已添加';
} else {
    $user_wechat_account = new UserWechatAccount();