=$length; } function LengthMax($val, $length) { return strlen($val)<=$length; } function NotEmpty($val) { return strlen($val)!=0;} function IsEmpty($val) { return strlen($val)==0; } function StripPhoneDashes($val) { if (preg_match("/^\d\d\d-\d\d\d-\d\d\d\d$/", $val) || preg_match("/^\d\d\d-\d\d\d-\d\d-\d\d$/", $val)) return str_replace("-", "", $val); else if (preg_match("/^1-\d\d\d-\d\d\d-\d\d\d\d$/", $val) || preg_match("/^1-\d\d\d-\d\d\d-\d\d-\d\d$/", $val)) return str_replace("-", "", substr($val, 2)); else return $val;} function IsPhone($val, $length = 10) { return IsNumeric($val) && LengthIs($val, $length);} function IsEmail($val) { return preg_match("/^([a-zA-Z0-9_\-\.\+]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/", $val);} ?> $value) { if ($key == "id" && $value == 0) continue; $fields [] = $key; $values [] = Sql($value); } $sql = "INSERT INTO " . $tablename . " (" . implode(",", $fields) . ") VALUES (" . implode(",", $values) . ")"; $ret = mysql_query($sql); if ($ret) $obj->id = mysql_insert_id(); return $ret; } function ObjectSqlUpdate($obj, $tablename = "") { if ($tablename == "") $tablename = strtolower(get_class($obj)) . "s"; $fields = array(); foreach ($obj as $key => $value) { if ($key == "id") continue; $fields [] = $key . "=" . Sql($value); } $sql = "UPDATE " . $tablename . " SET " . implode(",", $fields) . " WHERE id=" . $obj->id; $ret = mysql_query($sql); return $ret; } function ObjectSqlUpdate1($obj, $tablename = "", $primary_col = "id") { if ($tablename == "") $tablename = strtolower(get_class($obj)) . "s"; $fields = array(); foreach ($obj as $key => $value) { if ($key == $primary_col) continue; $fields [] = $key . "=" . Sql($value); } $sql = "UPDATE " . $tablename . " SET " . implode(",", $fields) . " WHERE " . $primary_col . "=" . $obj->$primary_col; $ret = mysql_query($sql); return $ret; } function ObjectSqlSave($obj, $tablename = "") { if ($obj->id == 0) return ObjectSqlInsert($obj, $tablename); else return ObjectSqlUpdate($obj, $tablename); } function ObjectFromArray($obj, $row) { foreach ($obj as $key => $value) if (isset($row[$key])) { if (is_bool($obj->$key)) $obj->$key = $row[$key] == "1"; else if (is_array($obj->$key) && is_string($row[$key])) $obj->$key = json_decode($row[$key], TRUE); else if (is_string($obj->$key) && is_array($row[$key])) $obj->$key = implode(",", $row[$key]); else if (is_string($obj->$key) && is_string($row[$key])) $obj->$key = stripslashes($row[$key]); else $obj->$key = $row[$key]; } } function ObjectSqlLoad($obj, $tablename = "") { if ($tablename == "") $tablename = strtolower(get_class($obj)) . "s"; if ($obj->id == 0) return; $res = mysql_query("SELECT * FROM " . $tablename . " WHERE id=" . $obj->id); if ($res != FALSE && mysql_num_rows($res) == 1) { $row = mysql_fetch_assoc($res); ObjectFromArray($obj, $row); mysql_free_result($res); return TRUE; } else return FALSE; } function ObjectsSqlLoad($sql, $classname) { $res = mysql_query($sql); if ($res != FALSE && mysql_num_rows($res) > 0) { $ret = array(); while ($row = mysql_fetch_assoc($res)) { $obj = new $classname(); ObjectFromArray($obj, $row); $ret [] = $obj; } return $ret; } else return FALSE; } function ObjectSqlDelete($obj, $tablename = "") { if ($tablename == "") $tablename = strtolower(get_class($obj)) . "s"; if ($obj->id == 0) return; $res = mysql_query("DELETE FROM " . $tablename . " WHERE id=" . $obj->id); return $res; } function DbQuery($sql, $pk = "") { $res = mysql_query($sql); //for INSERT, UPDATE, DELETE mysql_query returns TRUE or FALSE if ($res === TRUE || $res === FALSE) return $res; //handle if ($res) { //single value query if (mysql_num_fields($res) == 1 && mysql_num_rows($res) == 1) return mysql_result($res, 0); //empty result if (mysql_num_rows($res) == 0) return FALSE; $ret = array(); while ($row = mysql_fetch_assoc($res)) if (is_array($row) && count($row) > 0) { if ($pk == "") $ret [] = $row; else $ret[$row[$pk]] = $row; } mysql_free_result($res); return $ret; } return FALSE; } function LastDbError() { return mysql_error(); } function DeleteDir($dir) { $files = glob($dir . '*', GLOB_MARK); foreach ($files as $file) { if (is_dir($file)) DeleteDir($file); else unlink($file); } @rmdir($dir); } function DbConnect() { global $DB_SERVER, $DB_LOGIN, $DB_PASSWORD, $DB_NAME, $db_link; if (!$db_link) { $db_link = mysql_connect($DB_SERVER, $DB_LOGIN, $DB_PASSWORD) or die(mysql_error()); mysql_select_db($DB_NAME, $db_link) or die(mysql_error()); } } function DbClose() { global $db_link; mysql_close($db_link); $db_link = NULL; } function AnalyticsTableUnion($select = '*', $video_id = 0, $table_name = 'stat_video_', $where = '', $start = '', $end = '') { if ($start == '') $start = strtotime('Jun2012'); else $start = strtotime(date('MY', strtotime($start))); if ($end == '') $end = strtotime(date('MY')); else $end = strtotime(date('MY', strtotime($end))); $time = $start; $tbFromat = date('MY', $time); $query = "select $select from "; if (IsTableExist($table_name . $tbFromat)) $sql = "((select * from " . $table_name . $tbFromat . " where video_id=$video_id)"; while ($end >= $time) { $time = strtotime('+1 month', $time); $tbFromat = date('MY', $time); if (IsTableExist($table_name . $tbFromat)) { if ($sql != "") $sql .= " UNION (select * from " . $table_name . $tbFromat . " where video_id=$video_id) "; else $sql = "((select * from " . $table_name . $tbFromat . " where video_id=$video_id) "; } } $query .= $sql . ')as t1 ' . $where; return $query; } function IsTableExist($table_name) { if ($table_name != '') { $db = mysql_query("select * from $table_name limit 1"); if ($db) return true; else return false; } else return false; } function getValueByTagName( $data, $s_tag, $e_tag) { $pos = strpos($data, $s_tag); if ($pos === false) { return ''; } else { $s = strpos( $data,$s_tag) + strlen( $s_tag); $e = strlen( $data); $data= substr($data, $s, $e); $s = 0; $e = strpos( $data,$e_tag); $data= substr($data, $s, $e); $data= substr($data, $s, $e); return $data; } } function getIpAddress() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet $ip = $_SERVER['HTTP_CLIENT_IP']; elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; else $ip = $_SERVER['REMOTE_ADDR']; return $ip; } function saveUserAction($action = "", $userID = "", $ipAddress = ""){ $sql = "INSERT INTO `user_login_track` (`action`, `userid`, `ip_address`) VALUES ('".$action."', '".$userID."', '".$ipAddress."')"; mysql_query($sql); } DbConnect(); ?> EOT; } /* for trimmer only */ function GetEmbed_trimmer($player, $xmlpath, $w, $h, $stat, $isAnalytics, $player_swf, $secure, $rtmpFlag, $userid,$rtmp_url) { $id = "player" . rand(0, 100); $player = $player . '&this='.time(); $analytics = ""; if($isAnalytics == "Y") $analytics = "&isAnalytics=Y"; if($player_swf != "") $player_swf = "&skinURL=".$player_swf; //$rtmpFlag = 'false'; $rtmpFlag_temp = $rtmpFlag; $rtmpFlag = '&rtmpFlag='.$rtmpFlag; if($rtmpFlag_temp == 'true'){ $rtmpFlag .= '&userId='.$userid; //$rtmpFlag .= '&cURL=' .urlencode('rtmp://s302m963bxf8v6.cloudfront.net:1935/cfx/st/') ; //$rtmpFlag .= '&cURL=' .urlencode('rtmp://sp5besp3p52hd.cloudfront.net:1935/cfx/st/') ; $rtmpFlag .= '&cURL=' .urlencode($rtmp_url) ; } $h = $h + 60; return << EOT; } ?>id = $id; ObjectSqlLoad($this); } } public static function Load($id) { $ret = new MailTemplate(); $ret->id = $id; if (ObjectSqlLoad($ret)) return $ret; else return FALSE; } public static function LoadByName($name) { $id = DbQuery("SELECT id FROM mailtemplates WHERE name=" . Sql($name)); return MailTemplate::Load($id); } public function Save() { return ObjectSqlSave($this); } public function Apply($objectid, $videoCode = '', $videoErrorMess = '') { global $SITE; $class = $this->class; require_once $class . ".inc.php"; $obj = new $class($objectid); $text = $this->message; if (preg_match_all("/{([^}]*)}/", $this->message, $matches)) { for ($i = 0; $i < count($matches[0]); $i++) { $attribute = $matches[1][$i]; $replace = @$obj->$attribute; //If class is user and attribute is name if (strtolower($class) == 'user' && $attribute == 'name') { $parts = explode(' ', $replace); $replace = $parts[0]; } if($attribute == 'videolink'){ $replace = $SITE.'member/video.php?v='.$videoCode; } if($attribute == 'videoClickMagnetLink'){ $replace = $SITE.'clickmagnet/youtube_gif.php?id='.$videoCode; } if($attribute == 'videoError'){ $replace = $videoErrorMess; } $text = str_replace($matches[0][$i], $replace, $text); } } return $text; } public function ApplyAndSend($to, $objectid, $BccEmail = '', $videoCode = '', $videoErrorMess = '') { return MailTemplate::Send($to, $this->subject, $this->Apply($objectid, $videoCode, $videoErrorMess), '', '', $BccEmail); } public static function Send($to, $subject, $text, $name = '', $frommail = '', $BccEmail = '') { if (!function_exists('sendMailSES')) { require_once '/var/www/Live/repo/include/functions.php'; } if ($name == '' && $frommail == '') { $name = 'Easy Web Video'; $frommail = 'shawn@easywebvideo.com'; } return sendMailSES($to, $subject, $text, $frommail, $name, '', $BccEmail); if ($BccEmail) { $fm = "From: Easy Web Video \r\n"; $replay = "Reply-To:\r\n'"; $frommail = "shawn@easywebvideo.com"; } else if ($name == '' && $frommail == '') { $fm = "From: Easy Web Video \r\n"; $replay = "Reply-To:\r\n'"; $frommail = "shawn@easywebvideo.com"; } else { $fm = "From:" . $name . " \r\n"; $replay = "Reply-To:<" . $frommail . ">\r\n'"; } //$envFrom = '-f'.$frommail; $envFrom = ""; $headers = $fm . $replay . "MIME-Version: 1.0\r\n" . "Content-type: text/html; charset=utf-8\r\n"; if ($BccEmail) $headers .= "Bcc: " . $BccEmail . "\r\n"; return mail($to, $subject, $text, $headers, $envFrom); } public static function simpleSend($to, $subject, $text, $name = '', $frommail = '', $BccEmail = ''){ if (!function_exists('sendMailSES')) { require_once '/var/www/Live/repo/include/functions.php'; //require_once '../include/functions.php'; } if ($name == '' && $frommail == '') { $name = 'Easy Web Video'; } $replyto = $frommail; $frommail = 'support@easywebvideo.com'; return sendMailSES($to, $subject, $text, $frommail, $name, '', $BccEmail, $replyto); if ($BccEmail) { $fm = "From: Easy Web Video \r\n"; $replay = "Reply-To:\r\n'"; $frommail = "shawn@easywebvideo.com"; } else if ($name == '' && $frommail == '') { $fm = "From: Easy Web Video \r\n"; $replay = "Reply-To:\r\n'"; $frommail = "shawn@easywebvideo.com"; } else { $fm = "From:" . $name . " \r\n"; $replay = "Reply-To:<" . $frommail . ">\r\n'"; } //$envFrom = '-f'.$frommail; $envFrom = ""; $headers = $fm . $replay . "MIME-Version: 1.0\r\n" . "Content-type: text/html; charset=utf-8\r\n"; if ($BccEmail) $headers .= "Bcc: " . $BccEmail . "\r\n"; return mail($to, $subject, $text, $headers, $envFrom); } function simpleSend1($to, $subject, $text, $name = '', $frommail = '', $BccEmail = ''){ if ($BccEmail) { $fm = "From: Easy Web Video \r\n"; $replay = "Reply-To:\r\n'"; $frommail = "shawn@easywebvideo.com"; } else if ($name == '' && $frommail == '') { $fm = "From: Easy Web Video \r\n"; $replay = "Reply-To:\r\n'"; $frommail = "shawn@easywebvideo.com"; } else { $fm = "From:" . $name . " \r\n"; $replay = "Reply-To:<" . $frommail . ">\r\n'"; } //$envFrom = '-f'.$frommail; $envFrom = ""; $headers = $fm . $replay . "MIME-Version: 1.0\r\n" . "Content-type: text/html; charset=utf-8\r\n"; if ($BccEmail) $headers .= "Bcc: " . $BccEmail . "\r\n"; return mail($to, $subject, $text, $headers, $envFrom); } public static function sendMail($to, $subject, $text, $fromName, $fromEmail) { /* $mail = new PHPMailer; $mail->isSMTP(); $mail->isHTML(true); $mail->SMTPAuth = true; $mail->SMTPSecure = 'tls'; $mail->Host = 'email-smtp.us-east-1.amazonaws.com'; $mail->Port = 587; $mail->Username = 'AKIAICWOWB45AR3GR6SA'; $mail->Password = 'Aq8LRQGNJLncXFsSgDDyGAzzUVgI5R5uE9hRj5J+c1Mc'; $mail->setFrom($fromEmail, $fromName); $mail->AddReplyTo($fromEmail, $fromEmail); $mail->Subject = $subject; $mail->Body = $text;; $mail->AltBody = "This email was sent through the Amazon SES SMTP interface using the PHPMailer class."; foreach ($emails as $email) { $mail->ClearAddresses(); $mail->AddAddress($email); if(!$mail->send()) { echo "Email not sent. " , $mail->ErrorInfo , PHP_EOL; } else { echo "Email sent!" , PHP_EOL; } }*/ $mail = new PHPMailer(); $mail->IsSMTP(); $mail->IsHTML(true); // send as HTML $mail->SMTPAuth = true; // enable SMTP authentication $mail->SMTPSecure = "ssl"; // sets the prefix to the servier $mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server $mail->Port = 465; // set the SMTP port $mail->Username = "easywebv@gmail.com"; // GMAIL username $mail->Password = "easyartoon123"; // GMAIL password $mail->From = $fromEmail; $mail->FromName = $fromName; $mail->AddReplyTo($fromEmail, $fromEmail); $mail->Subject = $subject; $mail->Body = $text; //HTML Body $mail_sent = true; $emails = explode(",", $to); foreach ($emails as $email) { $mail->ClearAddresses(); $mail->AddAddress($email); $mail->Send(); } } } ?>