3f710487 by Marty Penner

Remove reliance on Tz\import (YEEESS)

1 parent 80749287
......@@ -43,8 +43,6 @@ const PASS_MAX_LEN = 15; // Maximum length of password
}
}
}
Tz\import('Tz', 'trunk');
});
/**
......
vendor/
\ No newline at end of file
{
"name": "tenzing/hybrid-gallery",
"require": {
"zendframework/zendframework1": "1.12.*"
},
"authors": [
{
"name": "Chris Boden",
"email": "cboden@gmail.com"
}
]
}
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "48a711bf2a9a641edb17c3599ffc1477",
"packages": [
{
"name": "zendframework/zendframework1",
"version": "1.12.7",
"source": {
"type": "git",
"url": "https://github.com/zendframework/zf1.git",
"reference": "bf3e8b557a5cef1b3f3c99636f8cdd93f884812a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zendframework/zf1/zipball/bf3e8b557a5cef1b3f3c99636f8cdd93f884812a",
"reference": "bf3e8b557a5cef1b3f3c99636f8cdd93f884812a",
"shasum": ""
},
"require": {
"php": ">=5.2.11"
},
"require-dev": {
"phpunit/dbunit": "1.3.*",
"phpunit/phpunit": "3.7.*"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.12.x-dev"
}
},
"autoload": {
"psr-0": {
"Zend_": "library/"
}
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
"library/"
],
"license": [
"BSD-3-Clause"
],
"description": "Zend Framework 1",
"homepage": "http://framework.zend.com/",
"keywords": [
"ZF1",
"framework"
],
"time": "2014-06-12 16:20:25"
}
],
"packages-dev": [
],
"aliases": [
],
"minimum-stability": "stable",
"stability-flags": [
],
"platform": [
],
"platform-dev": [
]
}
......@@ -2,262 +2,346 @@
//namespace Tz\WordPress\Tools\HybridGallery;
error_reporting(E_ALL ^ E_DEPRECATED);
//use Tz\WordPress\Tools;
require_once __DIR__.'/../../../../../wp-config.php';
require_once __DIR__.'/../vendor/autoload.php';
require_once("../../../../../wp-config.php");
Tz\import('Zend', '1.9');
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_HttpClient');
Zend_Loader::loadClass('Zend_Gdata_YouTube');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
function trace($d,$die = false) {
/**
* @param $d
* @param bool $die
*/
function trace($d, $die = false)
{
print "<pre>";
print_r($d);
print "</pre>";
if($die) { die('-- end of trace --'); }
if ($die) {
die('-- end of trace --');
}
}
class Forms {
protected $postdata = array();
protected $form = null;
protected $post_type = 'gallery';
protected $gallery = '';
/**
* Class Forms
*/
class Forms
{
protected $postdata = [];
protected $form = null;
protected $post_type = 'gallery';
protected $gallery = '';
protected $db;
protected $settings;
protected $requires_approval = "no";
public function __construct($db,$user) {
/**
* @param $db
* @param $user
*/
public function __construct($db, $user)
{
$this->db = $db;
$this->user = $user;
}
public function set_form($form_type) {
/**
* @param $form_type
*/
public function set_form($form_type)
{
$this->form = $form_type;
}
public function set_data($data = array()) {
/**
* @param array $data
*/
public function set_data($data = [])
{
if (count($data) > 0) {
// remove unecessary indexes.
unset($data['approval']);
unset($data['form_type']);
unset($data['gallery']);
$this->postdata = $this->_sanitize_data($data);
}
}
public function set_approval($a) {
/**
* @param $a
*/
public function set_approval($a)
{
$this->requires_approval = $a;
}
protected function getRealIpAddr() {
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;
}
public function set_gallery($gallery) {
$this->gallery = $gallery;
}
public function set_post_type($post_type) {
/**
* @param $post_type
*/
public function set_post_type($post_type)
{
$this->post_type = $post_type;
}
public function set_settings($setting) {
$this->settings[] = $settings;
}
protected function extractYouTubeVideoID($link = "") {
$parsed = @parse_url($link);
if($parsed) {
if(isset($parsed['query'])) {
$querystring = $parsed['query'];
@parse_str($querystring, $output);
if( isset($output['v']) && strlen($output['v']) > 1 ) {
return $output['v'];
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
}
protected function url_exists($url='') {
// Version 4.x supported
$handle = curl_init($url);
if (false === $handle) {
return false;
}
curl_setopt($handle, CURLOPT_HEADER, false);
curl_setopt($handle, CURLOPT_FAILONERROR, true); // this works
curl_setopt($handle, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") ); // request as if Firefox
curl_setopt($handle, CURLOPT_NOBODY, true);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, false);
$connectable = curl_exec($handle);
curl_close($handle);
return $connectable;
/**
* @param $setting
*/
public function set_settings($setting)
{
$this->settings[] = $setting;
}
public function create_entry() {
public function create_entry()
{
$gallery = $this->get_gallery($this->gallery);
$post = new hgPost();
$post->post_type = 'gallery';
$post->post_type = 'gallery';
if ($this->form == "image-form") {
$post->post_title = $this->postdata['title'];
$post->post_content = $this->postdata['description'];
$post->post_status = ($this->settings['image-approval'] == 'yes') ? 'pending' : 'publish';
$post->post_title = $this->postdata['title'];
$post->post_content = $this->postdata['description'];
$post->post_status = ($this->settings['image-approval'] == 'yes') ? 'pending' : 'publish';
// verified the link.
if(isset($this->postdata['imageLinked']) && $this->postdata['imageLinked'] != "") {
if (isset($this->postdata['imageLinked']) && $this->postdata['imageLinked'] != "") {
if (!$this->url_exists($this->postdata['imageLinked'])) {
die(json_encode(array('status'=>'error','details'=>"I'm sorry. We tried to find that image, but couldn't.")));
die(json_encode(
['status' => 'error', 'details' => "I'm sorry. We tried to find that image, but couldn't."]
));
}
}
$status = "verified";
$meta = array(
'gallery_type' => 'image'
, 'source' => (isset($this->postdata['imageLinked']) && $this->postdata['imageLinked'] != "") ? "linked" : "uploaded"
, 'link' => (isset($this->postdata['imageLinked']) && $this->postdata['imageLinked'] != "") ? $this->postdata['imageLinked'] : $this->postdata['uploaded_image_filename']
, 'views' => 0
, 'thumbnail' => ''
, 'tags' => ''
, 'status' => $status
);
if ($meta['source']=="uploaded") {
$meta = [
'gallery_type' => 'image',
'source' => (isset($this->postdata['imageLinked']) && $this->postdata['imageLinked'] != "")
? "linked" : "uploaded",
'link' => (isset($this->postdata['imageLinked']) && $this->postdata['imageLinked'] != "")
? $this->postdata['imageLinked'] : $this->postdata['uploaded_image_filename'],
'views' => 0,
'thumbnail' => '',
'tags' => '',
'status' => $status
];
if ($meta['source'] == "uploaded") {
$post->post_status = "pending";
}
//$wpdb = $this->db;
$post_id = wp_insert_post($post);
if($post_id < 1) {
die(json_encode(array('status'=>'error','details'=>"Could not create gallery post")));
if ($post_id < 1) {
die(json_encode(['status' => 'error', 'details' => "Could not create gallery post"]));
}
$this->db->query("INSERT INTO `".$this->db->prefix."term_relationships` (`object_id`,`term_taxonomy_id`) VALUES ($post_id,".$gallery['term_id'].")");
$this->db->query("UPDATE `".$this->db->prefix."term_taxonomy` SET `count`=(count+1) WHERE term_id=".$gallery['term_id']." LIMIT 1");
add_post_meta($post_id,'_gallery_item_details',$meta);
die(json_encode(array('status'=>'success','details'=>"Thank you for sharing!")));
$this->db->query(
"INSERT INTO `".$this->db->prefix."term_relationships` (`object_id`,`term_taxonomy_id`) VALUES ($post_id,"
.$gallery['term_id'].")"
);
$this->db->query(
"UPDATE `".$this->db->prefix."term_taxonomy` SET `count`=(count+1) WHERE term_id=".$gallery['term_id']
." LIMIT 1"
);
add_post_meta($post_id, '_gallery_item_details', $meta);
die(json_encode(['status' => 'success', 'details' => "Thank you for sharing!"]));
} else {
$post->post_status = ($this->settings['video-approval'] == 'yes') ? 'pending' : 'publish';
if ( isset($this->postdata['videoLinked']) && $this->postdata['videoLinked'] != "") {
if (isset($this->postdata['videoLinked']) && $this->postdata['videoLinked'] != "") {
$videoID = $this->extractYouTubeVideoID($this->postdata['videoLinked']);
if($videoID) {
if ($videoID) {
// go out and grab the video data....
$TzYouTubeConn = new Zend_Gdata_YouTube();
$TzYouTubeConn->setMajorProtocolVersion(2);
try {
$e = $TzYouTubeConn->getVideoEntry($videoID);
$thumbnail = "http://i.ytimg.com/vi/".$videoID."/0.jpg";
$post->post_title = htmlspecialchars( mysql_real_escape_string($e->getVideoTitle()) );
$post->post_content = htmlspecialchars( mysql_real_escape_string($e->getVideoDescription() ) );
$status = "verified";
$msg = "Thank you for sharing.";
$e = $TzYouTubeConn->getVideoEntry($videoID);
$thumbnail = "http://i.ytimg.com/vi/".$videoID."/0.jpg";
$post->post_title = htmlspecialchars(mysql_real_escape_string($e->getVideoTitle()));
$post->post_content = htmlspecialchars(mysql_real_escape_string($e->getVideoDescription()));
$status = "verified";
$msg = "Thank you for sharing.";
} catch (Exception $error) {
die(json_encode(array('status'=>'error','details'=>"I'm sorry. The video could not be verified with YouTube.")));
die(json_encode(
[
'status' => 'error',
'details' => "I'm sorry. The video could not be verified with YouTube."
]
));
}
} else {
die(json_encode(array('status'=>'error','details'=>"That YouTube video url is invalid.")));
die(json_encode(['status' => 'error', 'details' => "That YouTube video url is invalid."]));
}
} else {
$post->post_title = $this->postdata['video_title'];
$post->post_content = $this->postdata['video_description'];
$status = "unverified";
$msg = "Thank you for sharing. We are processing your video.";
$thumbnail = "";
$post->post_title = $this->postdata['video_title'];
$post->post_content = $this->postdata['video_description'];
$status = "unverified";
$msg = "Thank you for sharing. We are processing your video.";
$thumbnail = "";
}
$meta = array(
'gallery_type' => 'video'
, 'source' => (isset($this->postdata['videoLinked']) && $this->postdata['videoLinked'] != "") ? "linked" : "uploaded"
, 'link' => (isset($this->postdata['videoLinked']) && $this->postdata['videoLinked'] != "") ? $this->postdata['videoLinked'] : $this->postdata['uploaded_video_filename']
, 'views' => 0
, 'thumbnail' => $thumbnail
, 'tags' => ''
, 'status' => $status
);
$meta = [
'gallery_type' => 'video',
'source' => (isset($this->postdata['videoLinked']) && $this->postdata['videoLinked'] != "")
? "linked" : "uploaded",
'link' => (isset($this->postdata['videoLinked']) && $this->postdata['videoLinked'] != "")
? $this->postdata['videoLinked'] : $this->postdata['uploaded_video_filename'],
'views' => 0,
'thumbnail' => $thumbnail,
'tags' => '',
'status' => $status
];
$post_id = wp_insert_post($post);
$this->db->query("INSERT INTO `".$this->db->prefix."term_relationships` (`object_id`,`term_taxonomy_id`) VALUES ($post_id,".$gallery['term_id'].")");
$this->db->query("UPDATE `".$this->db->prefix."term_taxonomy` SET `count`=(count+1) WHERE term_id=".$gallery['term_id']." LIMIT 1");
$this->db->query(
"INSERT INTO `".$this->db->prefix."term_relationships` (`object_id`,`term_taxonomy_id`) VALUES ($post_id,"
.$gallery['term_id'].")"
);
$this->db->query(
"UPDATE `".$this->db->prefix."term_taxonomy` SET `count`=(count+1) WHERE term_id=".$gallery['term_id']
." LIMIT 1"
);
add_post_meta($post_id,'_gallery_item_details',$meta);
die(json_encode(array('status'=>'success','details'=>$msg)));
add_post_meta($post_id, '_gallery_item_details', $meta);
die(json_encode(['status' => 'success', 'details' => $msg]));
}
}
public function get_gallery($slug = '') {
$result = $this->db->get_row("SELECT t.term_id,t.name, tt.description FROM `".$this->db->prefix."terms` AS t, `".$this->db->prefix."term_taxonomy` as tt WHERE tt.term_id=t.term_id AND t.slug='$slug' LIMIT 1",'ARRAY_A');
/**
* @param string $slug
*
* @return mixed
*/
public function get_gallery($slug = '')
{
$result = $this->db->get_row(
"SELECT t.term_id,t.name, tt.description FROM `".$this->db->prefix."terms` AS t, `".$this->db->prefix
."term_taxonomy` as tt WHERE tt.term_id=t.term_id AND t.slug='$slug' LIMIT 1",
'ARRAY_A'
);
return $result;
}
protected function _sanitize_data($data = array()) {
$tempdata = array();
foreach($data as $option => $value) {
/**
* @param $gallery
*/
public function set_gallery($gallery)
{
$this->gallery = $gallery;
}
protected function getRealIpAddr()
{
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;
}
/**
* @param string $link
*
* @return bool
*/
protected function extractYouTubeVideoID($link = "")
{
$parsed = @parse_url($link);
if ($parsed) {
if (isset($parsed['query'])) {
$querystring = $parsed['query'];
@parse_str($querystring, $output);
if (isset($output['v']) && strlen($output['v']) > 1) {
return $output['v'];
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
}
/**
* @param string $url
*
* @return mixed
*/
protected function url_exists($url = '')
{
// Version 4.x supported
$handle = curl_init($url);
if (false === $handle) {
return false;
}
curl_setopt($handle, CURLOPT_HEADER, false);
curl_setopt($handle, CURLOPT_FAILONERROR, true); // this works
curl_setopt(
$handle,
CURLOPT_HTTPHEADER,
["User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15"]
); // request as if Firefox
curl_setopt($handle, CURLOPT_NOBODY, true);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, false);
$connectable = curl_exec($handle);
curl_close($handle);
return $connectable;
}
/**
* @param array $data
*
* @return array
*/
protected function _sanitize_data($data = [])
{
$tempdata = [];
foreach ($data as $option => $value) {
$tempdata[$option] = mysql_escape_string($value);
}
return $tempdata;
}
}
class hgPost {
var $post_title = '';
var $post_content = '';
var $post_status = 'publish';
var $post_type = 'gallery'; // can be 'page' or 'post'
/**
* Class hgPost
*/
class hgPost
{
var $post_title = '';
var $post_content = '';
var $post_status = 'publish';
var $post_type = 'gallery'; // can be 'page' or 'post'
var $comment_status = 'open'; // open or closed for commenting
}
$current_user = null;
get_currentuserinfo();
$form = new Forms($wpdb,$current_user);
$form = new Forms($wpdb, $current_user);
$form->set_form($_POST['form_type']);
$form->set_gallery($_POST['gallery']);
......@@ -265,5 +349,3 @@ $form->set_data($_POST);
$form->set_post_type('gallery');
$form->set_approval($_POST['approval']);
$form->create_entry();
?>
\ No newline at end of file
......
......@@ -7,8 +7,6 @@ const CAPABILITY = 'edit_user_details';
const HTML_NS = 'tzud-';
call_user_func(function() {
Tz\import('Tz', 'trunk');
$role = get_role('administrator');
$role->add_cap(CAPABILITY);
......