public static function feed_fb($token, $data) { $data = json_decode(base64_decode($data)); if (!empty($data->id)) { if (!defined('_PATH_PRODUCT_')) { define('_PATH_PRODUCT_', Config::get('base_url') . Config::get('app.path.product')); } $product = \Model_Base_Product::get_one($data->id); $tmp = "\r\n\r\n--------------------------------------------------\r\n\r\n"; $message = $product['product_name'] . $tmp . $product['product_description'] . $tmp . $product['product_info']; $groups = \Model_Base_GroupFb::get_all(); foreach ($groups as $group) { try { \OpauthStrategy::serverPost('https://graph.facebook.com/v2.5/' . $group['group_id'] . '/feed', array('access_token' => $token, 'message' => strip_tags(html_entity_decode($message, ENT_QUOTES)), 'link' => Uri::create('/product/' . $product['code']), 'caption' => 'WJ-SHOP', 'name' => html_entity_decode($product['product_name'], ENT_QUOTES), 'description' => html_entity_decode($product['product_description'], ENT_QUOTES), 'picture' => _PATH_PRODUCT_ . $product['product_photo']), null, $headers); } catch (\Exception $e) { Log::error($e->getMessage()); } sleep(5); } } elseif (!empty($data->message) && !empty($data->link)) { $groups = \Model_Base_GroupFb::get_all(); foreach ($groups as $group) { try { \OpauthStrategy::serverPost('https://graph.facebook.com/v2.5/' . $group['group_id'] . '/feed', array('access_token' => $token, 'message' => html_entity_decode($data->message, ENT_QUOTES), 'link' => $data->link), null, $headers); } catch (\Exception $e) { Log::error($e->getMessage()); } sleep(5); } } }
public static function sendToGCM($headers, $fields) { $url = 'https://android.googleapis.com/gcm/send'; // Open connection $ch = curl_init(); // Set the url curl_setopt($ch, CURLOPT_URL, $url); // Set request method to POST curl_setopt($ch, CURLOPT_POST, true); // Set custom headers curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // Get response back as string curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Set post data curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); // cacert curl_setopt($ch, CURLOPT_CAINFO, DOCROOT . 'assets/cacert.pem'); // Send the request $result = curl_exec($ch); $err = curl_error($ch); if (!empty($err)) { Log::debug($err); } else { Log::debug($result); } Log::debug(print_r($headers, 1)); Log::debug(print_r($fields, 1)); Log::debug(print_r(json_encode($fields), 1)); // Close connection curl_close($ch); // Debug GCM response return $result; }
/** * Logs a message with the Error Log Level * * @param string $msg The log message * @param string $method The method that logged * @return bool If it was successfully logged */ public static function error($msg, $method = null) { $tags = array(__METHOD__); $tags = $method !== null ? array_merge($tags, array($method)) : array(); static::amon($msg, $tags); return parent::write($msg, $method); }
public static function get_all($option = array()) { try { $category = Model_Category::find('all', array('select' => !empty($option['select']) ? $option['select'] : array(), 'where' => !empty($option['where']) ? $option['where'] : array(), 'order_by' => !empty($option['order_by']) ? $option['order_by'] : array('rank' => 'asc'))); return self::map_category($category); } catch (Exception $e) { Log::write('ERROR', $e->getMessage()); } return false; }
public static function get_one($id, $option = array()) { try { $data = Model_GroupFb::find('all', array('select' => !empty($option['all']) ? $option['select'] : array(), 'where' => !empty($option['where']) ? array_merge(array(array('id' => $id)), $option['where']) : array('id' => $id))); return self::map_data($data)[0]; } catch (Exception $e) { Log::write('ERROR', $e->getMessage()); } return false; }
public function select($searchKey) { try { $modelInstance = Model_Members::forge(); $result = Model_Members::query()->where('namefull', 'like', '%' . $searchKey . '%')->or_where('email', 'like', '%' . $searchKey . '%')->or_where('point', 'like', '%' . $searchKey . '%')->get(); return $result; } catch (Exception $error) { Log::error("MemberDao.select() : ", $error->getMessage()); return false; } }
public static function feed_fb($token, $data) { $data = base64_encode(json_encode($data)); $oil_path = str_replace('\\', '/', realpath(APPPATH . '/../../')); $command = "env FUEL_ENV=" . Fuel::$env . " php {$oil_path}/oil r tool:feed_fb '{$token}' '{$data}' > /dev/null &"; try { exec($command); } catch (Exception $e) { Log::error($e->getMessage()); } }
public static function delete($id) { try { $query = Model_Photo::find($id); $query->delete(); } catch (Exception $e) { Log::write('ERROR', $e->getMessage()); return false; } return true; }
public static function send_mail($option = null) { $option = base64_encode(json_encode($option)); $oil_path = str_replace('\\', '/', realpath(APPPATH . '/../../')); $command = "php {$oil_path}/oil r tool:send_mail '{$option}' "; try { exec($command); } catch (Exception $e) { Log::error($e->getMessage()); } return true; }
public static function load_highlight() { try { $dbResult = DB::SELECT('ID', 'Title', 'Description')->from('News')->where('Type', 2)->order_by('DateCreate', 'dsc')->limit(1)->execute(); $dbData = $dbResult->as_array(); return $dbData; } catch (\Exception $e) { Log::error($e); // Redirect to 500 server error; return Response::redirect(500); } }
public static function in_pages($page, $section_id) { // Start query with main section ID try { $dbResult = DB::SELECT('ID', 'Title', 'Description')->from('News')->where('Type', $section_id)->order_by('DateCreate', 'dsc')->limit(5)->offset($page * 5)->execute(); $dbData = $dbResult->as_array(); return $dbData; } catch (\Exception $e) { Log::error($e); // Redirect to 500 server error; return Response::redirect(500); } }
public static function update($data) { try { $data['updated_at'] = date('Y-m-d H:i:s', Date::forge()->get_timestamp()); $query = Model_Config::find(1); $query->set($data); $query->save(); } catch (Exception $e) { Log::write('ERROR', $e->getMessage()); return false; } return true; }
/** * Initialize the class */ public static function _init() { // Make sure that the file system structure stays intact. Also, create the $monolog instance. parent::_init(); // create the streamhandler, and activate the handler $stream = static::$monolog->popHandler(); $stream->setFormatter(new \Monolog\Formatter\CustomJsonFormatter()); static::$monolog->pushHandler($stream); // Processors static::$monolog->pushProcessor(new \Monolog\Processor\MemoryUsageProcessor()); static::$monolog->pushProcessor(new \Monolog\Processor\ProcessIdProcessor()); static::$monolog->pushProcessor(new \Monolog\Processor\WebProcessor()); static::$monolog->pushProcessor(new \Monolog\Processor\BitAPIHubProcessor()); }
/** * Auth request */ public function request() { $params = array('oauth_callback' => $this->strategy['oauth_callback']); $results = $this->_request('POST', $this->strategy['request_token_url'], $params); Log::error('$param:' . var_export($params, true)); Log::error('rt_url:' . $this->strategy['request_token_url']); Log::error('oauth:' . $results['oauth_token']); Log::error('oauth_secret:' . $results['oauth_token_secret']); Log::error('$results:' . var_export($results, true)); if ($results !== false && !empty($results['oauth_token']) && !empty($results['oauth_token_secret'])) { session_start(); $_SESSION['_opauth_twitter'] = $results; $this->_authorize($results['oauth_token']); } }
public static function update($product_id, $category_ids) { try { Model_ProductCategory::query()->where(array('product_id' => $product_id))->delete(); $props = array(); $category_ids = explode(',', $category_ids); foreach ($category_ids as $category_id) { $props[] = array($product_id, $category_id); } return Model_ProductCategory::insert($props); } catch (Exception $e) { Log::write('ERROR', $e->getMessage()); return false; } }
public static function insert($props) { try { $query = DB::insert(static::$_table_name)->columns(static::$_properties); foreach ($props as $prop) { $query->values($prop); } if ($query->execute()) { return true; } } catch (Exception $e) { Log::write('ERROR', $e->getMessage()); return false; } return false; }
public static function get_list() { $fieldList = array('ID', 'Name', 'Email', 'Phone', 'Sex', 'Major', 'DoB', 'PoB', 'PoO', 'Address'); try { /** @var Database_Query $dbObj */ $dbObj = DB::select_array($fieldList)->from(self::$TABLE); $dbResult = $dbObj->execute(); return count($dbResult) > 0 ? $dbResult->as_array() : []; } catch (\Exception $e) { Log::debug($e); return []; } $dbResult = DB::select_array($fieldList)->from(Staff::$TABLE)->execute(); $dbData = $dbResult->as_array(); return $dbData; }
public function action_send() { //CSRF対策 if (!Security::check_token()) { throw new HttpInvalidInputException('ページの遷移が正しくありません'); } $val = $this->forge_validation(); if (!$val->run()) { $this->template->title = 'コンタクトフォーム:エラー'; $this->template->content = View::forge('form/index'); $this->template->content->set_safe('html_error', $val->show_errors()); $this->template->footer = View::forge('form/footer'); return; } $post = $val->validated(); $data = $this->build_mail($post); //メールの送信 try { //$this->sendmail($data); Package::load('email'); $email = Email::forge(); $email->from($data['from'], $data['from_name']); $email->to($data['to'], $data['to_name']); $email->subject($data['subject']); $email->body($data['body']); $email->send(); $this->template->title = 'コンタクトフォーム:送信完了'; $this->template->content = View::forge('form/send'); $this->template->footer = View::forge('form/footer'); return; } catch (EmailValidationFailedException $e) { Log::error('メール検証エラー:' . $e->getmesseage(), __METHOD__); $html_error = '<p>メールアドレスに誤りがあります</p>'; } catch (EmailSendingFailedException $e) { Log::error('メール送信エラー:' . $e->getmesseage(), __METHOD__); $html_error = '<p>メールを送信できませんでした</p>'; } $this->template->title = 'コンタクトフォーム:送信エラー'; $this->template->content = View::forge('form/index'); $this->template->content->set_safe('html_error', $html_error); $this->template->footer = View::forge('form/footer'); }
public static function delete_user_provider($parent_id) { try { DB::delete('user_providers')->where('parent_id', '=', $parent_id)->execute(); } catch (Exception $e) { Log::write('ERROR', $e->getMessage()); return false; } return true; }
/** * check redirect * * @return void */ public function check_redirect() { if ($this->__skip === true) { return; } // check added www in production env if (\Fuel\Core\Fuel::$env === \Fuel\Core\Fuel::PRODUCTION) { if (!preg_match('/^' . \Config::get('seo.subdomain') . '\\./', $_SERVER['HTTP_HOST'])) { $new_uri = \Fuel\Core\Input::protocol() . '://' . \Config::get('seo.subdomain') . '.' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; \Fuel\Core\Response::redirect($new_uri, 'location', 301); } } // init $redirect_flg = false; $redirect_uri = $this->_current_uri . $this->_current_get; // reverse routing $check_uri = Route::reverse_route($this->_routed_uri); if ($check_uri !== $this->_routed_uri or $check_uri !== $this->_current_uri) { $redirect_flg = true; $redirect_uri = $check_uri . $this->_current_get; } // page=1 check (301 redirect) if (\Fuel\Core\Input::get('page') === '1') { $redirect_flg = true; $redirect_uri = preg_replace('/[&?](page=1&?)/', '$1', $redirect_uri); } // last &, ? check (301 redirect) if (empty(\Input::get()) and preg_match('/[&\\?]$/', $redirect_uri)) { $redirect_flg = true; $redirect_uri = preg_replace('/[&\\?]$/', '', $redirect_uri); } // do 301 redirect if ($redirect_flg) { \Fuel\Core\Session::keep_flash(); // before redirect, if env is development and posted, set notify if (\Fuel\Core\Fuel::$env === \Fuel\Core\Fuel::DEVELOPMENT and \Fuel\Core\Input::post()) { \Fuel\Core\Session::set_flash('error', 'Redirect occured, please check post url'); } \Fuel\Core\Log::debug($this->_current_uri . $this->_current_get . ': redirect to ' . $redirect_uri); \Fuel\Core\Response::redirect($redirect_uri, 'location', 301); } }
public static function get_by_category_ids($category_ids, $offset = _DEFAULT_OFFSET_, $limit = _DEFAULT_LIMIT_) { $ids = join(',', $category_ids); $sql = "\n SELECT `p`.*\n FROM `product_categories` `pc`\n LEFT JOIN `products` `p` ON `pc`.`product_id` = `p`.`id`\n WHERE `pc`.`category_id` IN ({$ids})\n AND `p`.`status` = 1\n GROUP BY `p`.`id`\n ORDER BY `p`.`id` DESC\n LIMIT {$offset}, {$limit}\n "; try { $product = DB::query($sql)->as_object()->execute(); return self::map_product($product); } catch (Exception $e) { Log::write('ERROR', $e->getMessage()); } return false; }
public function deleteStory($id) { try { $dbObj = DB::delete($this->TABLE)->where('ID', $id); $dbObj->execute(); return true; } catch (\Exception $e) { Log::debug($e); return false; } }
/** * Goes and try's to create a connection to the MongoClient through the Monga Connection class. If a connection * cannot be made it tries to attempt a new connection until it has reached its maximum retry's. If this is the * case the function throws an exception stating that it cannot currently connect to the MongoDB Client. This code * is based off of an issue in the PHP Legacy driver, issue PHP-854. The URL to that issue is: * * https://jira.mongodb.org/browse/PHP-854 * * The workaround to the issue was posted on Nov 14 2013 07:21:18 PM GMT+0000 by Hannes Magnusson. * * @param string $dsn The Information for what mongo client(s) to connect to. * @param array $options All of the options for creating the MongoClient * @param int $retry How many times we should try and retry creating a connection * @return \League\Monga\Connection The connection for the Monga object. * @throws \Exception */ protected static function get_connection($dsn, $options, $retry = self::MAX_CONNECTION_RETRY_COUNT) { try { $instance = Monga::connection($dsn, $options); return $instance; } catch (\Exception $e) { Log::error('Exception thrown: (' . __FILE__ . '#' . __LINE__ . '): ' . $e->getMessage()); } if ($retry > 0) { $retry--; return static::get_connection($dsn, $options, $retry); } else { throw new \Exception(self::CANNOT_CONNECT_EXCEPTION); } }
public static function _init() { \Fluent\Autoloader::register(); parent::_init(); }