/docroot/wp-content/plugins/zannel-tools/zannel-tools.php
PHP | 2736 lines | 2116 code | 250 blank | 370 comment | 329 complexity | 9961694b15d320c208adcde48c7526fe MD5 | raw file
Possible License(s): LGPL-2.1, GPL-3.0, GPL-2.0, BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
- <?php
- /*
- Plugin Name: Zannel Tools
- Plugin URI: http://zannel.com
- Description: A complete integration between your WordPress blog and <a href="http://zannel.com">Zannel</a>. Bring your Zannel Updates into your blog and pass your blog posts back to Zannel.
- Version: 1.0
- Author: Crowd Favorite
- Author URI: http://crowdfavorite.com
-
- Template Tags:
- Latest update: <?php cfzt_latest_zupdate(); ?>
- List of updates: <?php cfzt_sidebar_zupdates(); ?>
- */
-
- // Released under the GPL license
- // http://www.opensource.org/licenses/gpl-license.php
- //
- // This is an add-on for WordPress
- // http://wordpress.org/
- //
- // Based on Twitter Tools by Crowd Favorite, Ltd.
- //
- // **********************************************************************
- // 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.
- // **********************************************************************
-
- load_plugin_textdomain('zannel-tools');
-
- if (!defined('PLUGINDIR')) {
- define('PLUGINDIR','wp-content/plugins');
- }
-
- if (is_file(trailingslashit(ABSPATH.PLUGINDIR).'zannel-tools.php')) {
- define('CFZT_FILE', trailingslashit(ABSPATH.PLUGINDIR).'zannel-tools.php');
- }
- else if (is_file(trailingslashit(ABSPATH.PLUGINDIR).'zannel-tools/zannel-tools.php')) {
- define('CFZT_FILE', trailingslashit(ABSPATH.PLUGINDIR).'zannel-tools/zannel-tools.php');
- }
-
- if (!function_exists('is_admin_page')) {
- function is_admin_page() {
- if (function_exists('is_admin')) {
- return is_admin();
- }
- if (function_exists('check_admin_referer')) {
- return true;
- }
- else {
- return false;
- }
- }
- }
-
- if (!function_exists('wp_prototype_before_jquery')) {
- function wp_prototype_before_jquery( $js_array ) {
- if ( false === $jquery = array_search( 'jquery', $js_array ) )
- return $js_array;
-
- if ( false === $prototype = array_search( 'prototype', $js_array ) )
- return $js_array;
-
- if ( $prototype < $jquery )
- return $js_array;
-
- unset($js_array[$prototype]);
-
- array_splice( $js_array, $jquery, 0, 'prototype' );
-
- return $js_array;
- }
-
- add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' );
- }
-
- define('CFZT_API_POST_UPDATE', 'http://app.zannel.com/api/update.json');
- define('CFZT_API_GET_UPDATES', 'http://app.zannel.com/api/user/###USERNAME###/updates.json');
- define('CFZT_API_COMMENT_URL', 'http://app.zannel.com/api/update/###ZUPDATEHASH###/comments.json');
- define('CFZT_PROFILE_URL', 'http://zannel.com/###USERNAME###');
- define('CFZT_TEST_LOGIN_URL', 'http://app.zannel.com/api/user/###USERNAME###.json');
-
- function cfzt_install() {
- global $wpdb;
-
- $cfzt_install = new zannel_tools;
- $wpdb->cfzt = $wpdb->prefix.'cfzt_zannel';
- $charset_collate = '';
- if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) {
- if (!empty($wpdb->charset)) {
- $charset_collate .= " DEFAULT CHARACTER SET $wpdb->charset";
- }
- if (!empty($wpdb->collate)) {
- $charset_collate .= " COLLATE $wpdb->collate";
- }
- }
- $result = $wpdb->query("
- CREATE TABLE `$wpdb->cfzt` (
- `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
- `zupdate_hash` VARCHAR( 255 ) NOT NULL ,
- `zupdate_type` VARCHAR( 255 ) NOT NULL ,
- `zupdate_tags` VARCHAR( 255 ) NOT NULL ,
- `zupdate_timestamp` VARCHAR( 255 ) NOT NULL ,
- `zupdate_description` VARCHAR( 255 ) NOT NULL ,
- `zupdate_user` VARCHAR( 255 ) NOT NULL ,
- `zupdate_media` VARCHAR( 500 ) ,
- `zupdate_embed_code` VARCHAR ( 500 ) ,
- `zupdate_url` VARCHAR( 255 ) NOT NULL ,
- `modified` DATETIME NOT NULL ,
- INDEX ( `zupdate_hash` )
- ) $charset_collate
- ");
- foreach ($cfzt_install->options as $option) {
- add_option('cfzt_'.$option, $cfzt_install->$option);
- }
- add_option('cfzt_zupdate_hash', '');
- }
- register_activation_hook(CFZT_FILE, 'cfzt_install');
-
- class zannel_tools {
- function zannel_tools() {
- $this->options = array(
- 'zannel_username'
- , 'zannel_password'
- , 'create_blog_posts'
- , 'default_post_title'
- , 'create_digest'
- , 'create_digest_weekly'
- , 'digest_daily_time'
- , 'digest_weekly_time'
- , 'digest_weekly_day'
- , 'digest_title'
- , 'digest_title_weekly'
- , 'blog_post_author'
- , 'blog_post_category'
- , 'blog_post_tags'
- , 'notify_zannel'
- , 'sidebar_zupdate_count'
- , 'zupdate_from_sidebar'
- , 'give_cfzt_credit'
- , 'exclude_reply_zupdates'
- , 'last_zupdate_download'
- , 'doing_zupdate_download'
- , 'doing_digest_post'
- , 'install_date'
- , 'js_lib'
- , 'digest_zupdate_order'
- , 'notify_zannel_default'
- );
- $this->zannel_username = '';
- $this->zannel_password = '';
- $this->create_blog_posts = '0';
- $this->default_post_title = 'New Update from Zannel!';
- $this->create_digest = '0';
- $this->create_digest_weekly = '0';
- $this->digest_daily_time = null;
- $this->digest_weekly_time = null;
- $this->digest_weekly_day = null;
- $this->digest_title = __("Zannel Updates for %s", 'zannel-tools');
- $this->digest_title_weekly = __("Zannel Weekly Updates for %s", 'zannel-tools');
- $this->blog_post_author = '1';
- $this->blog_post_category = '1';
- $this->blog_post_tags = '';
- $this->notify_zannel = '0';
- $this->notify_zannel_default = '0';
- $this->sidebar_zupdate_count = '3';
- $this->zupdate_from_sidebar = '1';
- $this->give_cfzt_credit = '1';
- $this->exclude_reply_zupdates = '0';
- $this->install_date = '';
- $this->js_lib = 'jquery';
- $this->digest_zupdate_order = 'ASC';
- // not included in options
- $this->update_hash = '';
- $this->zupdate_prefix = 'New blog post';
- $this->zupdate_format = $this->zupdate_prefix.': %s %s';
- $this->last_digest_post = '';
- $this->last_zupdate_download = '';
- $this->doing_zupdate_download = '0';
- $this->doing_digest_post = '0';
- $this->version = '1.0';
- }
-
- function get_settings() {
- foreach ($this->options as $option) {
- $this->$option = get_option('cfzt_'.$option);
- }
- }
-
- // puts post fields into object propps
- function populate_settings() {
- foreach ($this->options as $option) {
- if (isset($_POST['cfzt_'.$option])) {
- $this->$option = stripslashes($_POST['cfzt_'.$option]);
- }
- }
- }
-
- // puts object props into wp option storage
- function update_settings() {
- if (current_user_can('manage_options')) {
- $this->sidebar_zupdate_count = intval($this->sidebar_zupdate_count);
- if ($this->sidebar_zupdate_count == 0) {
- $this->sidebar_zupdate_count = '3';
- }
- foreach ($this->options as $option) {
- update_option('cfzt_'.$option, $this->$option);
- }
- if (empty($this->install_date)) {
- update_option('cfzt_install_date', current_time('mysql'));
- }
- $this->initiate_digests();
- }
- }
-
- // figure out when the next weekly and daily digests will be
- function initiate_digests() {
- $next = ($this->create_digest) ? $this->calculate_next_daily_digest() : null;
- $this->next_daily_digest = $next;
- update_option('cfzt_next_daily_digest', $next);
-
- $next = ($this->create_digest_weekly) ? $this->calculate_next_weekly_digest() : null;
- $this->next_weekly_digest = $next;
- update_option('cfzt_next_weekly_digest', $next);
- }
-
- function calculate_next_daily_digest() {
- $optionDate = strtotime($this->digest_daily_time);
- $hour_offset = date("G", $optionDate);
- $minute_offset = date("i", $optionDate);
- $next = mktime($hour_offset, $minute_offset, 0);
-
- // may have to move to next day
- $now = time();
- while ($next < $now) {
- $next += 60 * 60 * 24;
- }
- return $next;
- }
-
- function calculate_next_weekly_digest() {
- $optionDate = strtotime($this->digest_weekly_time);
- $hour_offset = date("G", $optionDate);
- $minute_offset = date("i", $optionDate);
-
- $current_day_of_month = date("j");
- $current_day_of_week = date("w");
- $current_month = date("n");
-
- // if this week's day is less than today, go for next week
- $nextDay = $current_day_of_month - $current_day_of_week + $this->digest_weekly_day;
- if ($this->digest_weekly_day <= $current_day_of_week) {
- $nextDay += 7;
- }
-
- $next = mktime($hour_offset, $minute_offset, 0, $current_month, $nextDay);
-
- return $next;
- }
-
- function ping_digests() {
- // still busy
- if (get_option('cfzt_doing_digest_post') == '1') {
- return;
- }
- // check all the digest schedules
- if ($this->create_digest == 1) {
- $this->ping_digest('cfzt_next_daily_digest', 'cfzt_last_digest_post', $this->digest_title, (60 * 60 * 24 * 1));
- }
- if ($this->create_digest_weekly == 1) {
- $this->ping_digest('cfzt_next_weekly_digest', 'cfzt_last_digest_post_weekly', $this->digest_title_weekly, (60 * 60 * 24 * 7));
- }
- return;
- }
-
- function ping_digest($nextDateField, $lastDateField, $title, $defaultDuration) {
- $next = get_option($nextDateField);
-
- if ($next) {
- $next = $this->validateDate($next);
- $rightNow = time();
- if ($rightNow >= $next) {
- $start = get_option($lastDateField);
- $start = $this->validateDate($start, ($rightNow - $defaultDuration));
- if ($this->do_digest_post($start, $next, $title)) {
- update_option($lastDateField, $rightNow);
- update_option($nextDateField, ($next + $defaultDuration));
- } else {
- update_option($lastDateField, null);
- }
- }
- }
- }
-
- function validateDate($in, $default = 0) {
- if (!is_numeric($in)) {
- // try to convert what they gave us into a date
- $out = strtotime($in);
- // if that doesn't work, return the default
- if (!is_numeric($out)) {
- return $default;
- }
- return $out;
- }
- return $in;
- }
-
- function do_digest_post($start, $end, $title) {
- if (!$start || !$end) return false;
- // flag us as busy
- update_option('cfzt_doing_digest_post', '1');
- remove_action('publish_post', 'cfzt_notify_zannel', 99);
- remove_action('publish_post', 'cfzt_store_post_options', 1, 2);
- remove_action('save_post', 'cfzt_store_post_options', 1, 2);
- // see if there's any updates in the time range
- global $wpdb;
-
- $startGMT = gmdate("Y-m-d H:i:s", $start);
- $endGMT = gmdate("Y-m-d H:i:s", $end);
-
- // build sql
- $conditions = array();
- $conditions[] = "zupdate_timestamp >= '{$startGMT}'";
- $conditions[] = "zupdate_timestamp <= '{$endGMT}'";
- $conditions[] = "zupdate_description NOT LIKE '$this->zupdate_prefix%'";
- if ($this->exclude_reply_zupdates) {
- $conditions[] = "zupdate_description NOT LIKE '@%'";
- }
- $where = implode(' AND ', $conditions);
-
- $sql = "
- SELECT * FROM {$wpdb->cfzt}
- WHERE {$where}
- GROUP BY id
- ORDER BY zupdate_timestamp {$this->digest_zupdate_order}
- ";
-
- $zupdates = $wpdb->get_results($sql);
-
- if (count($zupdates) > 0) {
-
- $zupdates_to_post = array();
- foreach ($zupdates as $data) {
- $zupdate = new cfzt_zupdate;
- $zupdate->description = $data->description;
- $zupdate->cfzt_reply_zupdate = $data->cfzt_reply_zupdate;
- if (!$zupdate->zupdate_is_post_notification() || ($zupdate->zupdate_is_reply() && $this->exclude_reply_zupdates)) {
- $zupdates_to_post[] = $data;
- }
- }
-
- if (count($zupdates_to_post) > 0) {
- $content = '<ul class="cfzt_zupdate_digest">'."\n";
- foreach ($zupdates_to_post as $zupdate) {
- $content .= ' <li>'.cfzt_zupdate_display($zupdate, 'absolute').'</li>'."\n";
- }
- $content .= '</ul>'."\n";
- if ($this->give_cfzt_credit == '1') {
- $content .= '<p class="cfzt_credit">Powered by <a href="http://zannel.com">Zannel Tools</a>.</p>';
- }
-
- $post_data = array(
- 'post_content' => $wpdb->escape($content),
- 'post_title' => $wpdb->escape(sprintf($title, date('Y-m-d'))),
- 'post_date' => date('Y-m-d H:i:s', $end),
- 'post_category' => array($this->blog_post_category),
- 'post_status' => 'publish',
- 'post_author' => $wpdb->escape($this->blog_post_author)
- );
-
- $post_id = wp_insert_post($post_data);
-
- add_post_meta($post_id, 'cfzt_zupdated', '1', true);
- wp_set_post_tags($post_id, $this->blog_post_tags);
- }
-
- }
- add_action('publish_post', 'cfzt_notify_zannel', 99);
- add_action('publish_post', 'cfzt_store_post_options', 1, 2);
- add_action('save_post', 'cfzt_store_post_options', 1, 2);
- update_option('cfzt_doing_digest_post', '0');
- return true;
- }
-
- function zupdate_download_interval() {
- return 1800;
- }
-
- function do_zupdate($zupdate = '') {
- if (empty($this->zannel_username)
- || empty($this->zannel_password)
- || empty($zupdate)
- || empty($zupdate->zupdate_description)
- ) {
- return;
- }
- require_once(ABSPATH.WPINC.'/class-snoopy.php');
- $snoop = new Snoopy;
- $snoop->agent = 'Zannel Tools http://zannel.com';
- $snoop->rawheaders = array(
- 'X-Zannel-Client' => 'Zannel Tools'
- , 'X-Zannel-Client-Version' => $this->version
- , 'X-Zannel-Client-URL' => 'http://zannel.com'
- );
- $snoop->set_submit_multipart();
- $data_arguments = array(
- 'authuser' => $this->zannel_username,
- 'authpass' => $this->zannel_password,
- 'description' => $zupdate->zupdate_description
- );
- if ($zupdate->media) {
- $snoop->submit(
- CFZT_API_POST_UPDATE
- , $data_arguments
- , $zupdate->media
- );
- }
- else {
- $snoop->submit(
- CFZT_API_POST_UPDATE
- , $data_arguments
- );
- }
- if (strpos($snoop->response_code, '200')) {
- update_option('cfzt_last_zupdate_download', strtotime('-28 minutes'));
- return true;
- }
- return false;
- }
-
- function do_blog_post_zupdate($post_id = 0) {
- if ($this->notify_zannel == '0'
- || $post_id == 0
- || get_post_meta($post_id, 'cfzt_zupdated', true) == '1'
- || get_post_meta($post_id, 'cfzt_notify_zannel', true) == 'no'
- ) {
- return;
- }
- $post = get_post($post_id);
- // check for an edited post before TT was installed
- if ($post->post_date <= $this->install_date) {
- return;
- }
- // check for private posts
- if ($post->post_status != 'publish') {
- return;
- }
- $zupdate = new cfzt_zupdate;
- $url = apply_filters('zupdate_blog_post_url', get_permalink($post_id));
- $zupdate->zupdate_description = sprintf(__($this->zupdate_format, 'zannel-tools'), $post->post_title, $url);
- $zupdate->media = $this->get_post_media($post_id);
-
- $this->do_zupdate($zupdate);
- add_post_meta($post_id, 'cfzt_zupdated', '1', true);
- }
- function get_post_media($post_id) {
- global $wpdb;
- $sql = '
- SELECT ID
- FROM '.$wpdb->posts.'
- WHERE post_type="attachment"
- AND post_parent='.$post_id.'
- ';
- $attachment_ids = $wpdb->get_results($sql);
- if (!$attachment_ids) {
- return false;
- }
- $path_to_uploads = wp_upload_dir();
- $path_to_media = trailingslashit($path_to_uploads['basedir']);
- $biggest_file = '';
- $biggest_file_size = '';
- foreach ($attachment_ids as $attachment) {
- $media = get_post_meta($attachment->ID,'_wp_attached_file',true);
- if (!empty($media)) {
- if (version_compare(get_bloginfo('version'),'2.6.5','>')) {
- // 2.7 gives us a relative path, while 2.6.5 and 2.5.1 give us a full path
- $media = $path_to_media.$media;
- }
- $file_size = filesize($media);
- if ($file_size >= $biggest_file_size) {
- $biggest_file = $media;
- $biggest_file_size = $file_size;
- }
- }
- }
- return $biggest_file;
- }
- function do_zupdate_post($zupdate) {
- global $wpdb;
- remove_action('publish_post', 'cfzt_notify_zannel', 99);
- remove_action('publish_post', 'cfzt_store_post_options', 1, 2);
- remove_action('save_post', 'cfzt_store_post_options', 1, 2);
- // if post type is video, then grab embed code
- if ($zupdate->type == "VIDEO") {
- $post_content = $zupdate->description.'<p>'.$zupdate->embed_code.'</p>';
- }
- else if ($zupdate->type == "IMAGE") {
- $media = unserialize($zupdate->media);
- $post_content = $zupdate->description.'<p><img src="'.$media->large.'" /></p>';
- }
- else {
- $post_content = $zupdate->description;
- }
- if (empty($zupdate->description)) {
- // we need a post title, so if it's empty, use the default one.
- $post_title = get_option('cfzt_default_post_title');
- }
- if ($this->exclude_reply_zupdates && ereg('^@',$zupdate->description)) {
- // don't create post if is reply and exclude replies is set
- return;
- }
- else {
- $post_title = $zupdate->description;
- }
- $data = array(
- 'post_content' => $wpdb->escape(cfzt_make_clickable($post_content))
- , 'post_title' => $wpdb->escape(trim_add_elipsis($post_title, 30))
- , 'post_date' => get_date_from_gmt(gmdate('Y-m-d H:i:s', strtotime($zupdate->timestamp)))
- , 'post_category' => array($this->blog_post_category)
- , 'post_status' => 'publish'
- , 'post_author' => $wpdb->escape($this->blog_post_author)
- );
- $post_id = wp_insert_post($data);
- update_post_meta($post_id, 'cfzt_notify_zannel', 'no', true);
- add_post_meta($post_id, 'cfzt_zupdate_id', $zupdate->hashcode, true);
- wp_set_post_tags($post_id, $this->blog_post_tags);
- add_action('publish_post', 'cfzt_notify_zannel', 99);
- add_action('publish_post', 'cfzt_store_post_options', 1, 2);
- add_action('save_post', 'cfzt_store_post_options', 1, 2);
- }
- }
-
- class cfzt_zupdate {
- function cfzt_zupdate(
- $hashcode = '',
- $type = '',
- $tags = '',
- $timestamp = '',
- $description = '',
- $user = '',
- $media = '',
- $embed_code = '',
- $url = ''
- ){
- $this->id = '';
- $this->hashcode = $hashcode;
- $this->type = $type;
- $this->tags = $tags;
- $this->timestamp = $timestamp;
- $this->description = $description;
- $this->user = $user;
- $this->media = $media;
- $this->embed_code = $embed_code;
- $this->url = $url;
- $this->modified = '';
- }
-
- function cfztdate_to_time($date) {
- $parts = explode(' ', $date);
- $date = strtotime($parts[1].' '.$parts[2].', '.$parts[5].' '.$parts[3]);
- return $date;
- }
-
- function zupdate_post_exists() {
- global $wpdb;
- $test = $wpdb->get_results("
- SELECT *
- FROM $wpdb->postmeta
- WHERE meta_key = 'cfzt_zupdate_id'
- AND meta_value = '".$wpdb->escape($this->hashcode)."'
- ");
- if (count($test) > 0) {
- return true;
- }
- return false;
- }
-
- function zupdate_is_post_notification() {
- global $cfzt;
- if (substr($this->description, 0, strlen($cfzt->zupdate_prefix)) == $cfzt->zupdate_prefix) {
- return true;
- }
- return false;
- }
-
- function zupdate_is_reply() {
- return !empty($this->cfzt_reply_zupdate);
- }
-
- function add() {
- global $wpdb, $cfzt;
- $wpdb->query("
- INSERT
- INTO $wpdb->cfzt
- ( id
- , zupdate_hash
- , zupdate_type
- , zupdate_tags
- , zupdate_timestamp
- , zupdate_description
- , zupdate_user
- , zupdate_media
- , zupdate_embed_code
- , zupdate_url
- , modified
- )
- VALUES
- ( '".$wpdb->escape($this->id)."'
- , '".$wpdb->escape($this->hashcode)."'
- , '".$wpdb->escape($this->type)."'
- , '".$wpdb->escape($this->tags)."'
- , '".date('Y-m-d H:i:s', strtotime($this->timestamp))."'
- , '".$wpdb->escape($this->description)."'
- , '".$wpdb->escape($this->user)."'
- , '".$wpdb->escape($this->media)."'
- , '".$wpdb->escape($this->embed_code)."'
- , '".$wpdb->escape($this->url)."'
- , NOW()
- )
- ");
- do_action('cfzt_add_zupdate', $this);
-
- if ($cfzt->create_blog_posts == '1' && !$this->zupdate_post_exists() && !$this->zupdate_is_post_notification()) {
- $cfzt->do_zupdate_post($this);
- }
- }
- }
-
- function cfzt_api_status_show_url($id) {
- return str_replace('###ID###', $id, CFZT_API_STATUS_SHOW);
- }
-
- function cfzt_profile_url($username) {
- return str_replace('###USERNAME###', $username, CFZT_PROFILE_URL);
- }
-
- function cfzt_profile_link($username, $prefix = '', $suffix = '') {
- return $prefix.'<a href="'.cfzt_profile_url($username).'">'.$username.'</a>'.$suffix;
- }
-
- function cfzt_hashtag_url($hashtag) {
- $hashtag = urlencode('#'.$hashtag);
- return str_replace('###HASHTAG###', $hashtag, CFZT_HASHTAG_URL);
- }
-
- function cfzt_hashtag_link($hashtag, $prefix = '', $suffix = '') {
- return $prefix.'<a href="'.cfzt_hashtag_url($hashtag).'">'.htmlspecialchars($hashtag).'</a>'.$suffix;
- }
-
- function cfzt_status_url($username, $status) {
- return str_replace(
- array(
- '###USERNAME###'
- , '###STATUS###'
- )
- , array(
- $username
- , $status
- )
- , CFZT_STATUS_URL
- );
- }
-
- function cfzt_login_test($username, $password) {
- require_once(ABSPATH.WPINC.'/class-snoopy.php');
- $snoop = new Snoopy;
- $snoop->agent = 'Zannel Tools http://zannel.com';
- $snoop->user = $username;
- $snoop->pass = $password;
- $arguments = array(
- 'zannel_login_test' => 'test'
- );
- $snoop->submit(str_replace('###USERNAME###',$username,CFZT_TEST_LOGIN_URL),$arguments);
- if (strpos($snoop->response_code, '200')) {
- return __("Login succeeded, you're good to go.", 'zannel-tools');
- } else {
- return print(__('Sorry, login failed. Please check your username and password', 'zannel-tools'));
- }
- }
-
-
- function cfzt_ping_digests() {
- global $cfzt;
- $cfzt->ping_digests();
- }
-
- function cfzt_update_zupdates() {
- // let the last update run for 10 minutes
- if (time() - intval(get_option('cfzt_doing_zupdate_download')) < 600) {
- return;
- }
- // wait 10 min between downloads
- if (time() - intval(get_option('cfzt_last_zupdate_download')) < 600) {
- return;
- }
- update_option('cfzt_doing_zupdate_download', time());
- global $wpdb, $cfzt;
- if (empty($cfzt->zannel_username) || empty($cfzt->zannel_password)) {
- update_option('cfzt_doing_zupdate_download', '0');
- return;
- }
- require_once(ABSPATH.WPINC.'/class-snoopy.php');
- $snoop = new Snoopy;
- $snoop->agent = 'Zannel Tools http://zannel.com';
- $snoop->user = $cfzt->zannel_username;
- $snoop->pass = $cfzt->zannel_password;
- $url = str_replace('###USERNAME###',$cfzt->zannel_username,CFZT_API_GET_UPDATES);
- $snoop->fetch($url);
- if (!strpos($snoop->response_code, '200')) {
- update_option('cfzt_doing_zupdate_download', '0');
- return;
- }
- $data = $snoop->results;
- // hash results to see if they're any different than the last update, if so, return
- $hash = md5($data);
- if ($hash == get_option('cfzt_zupdate_hash')) {
- update_option('cfzt_last_zupdate_download', time());
- update_option('cfzt_doing_zupdate_download', '0');
- return;
- }
- $json = new Services_JSON();
- $zupdates = $json->decode($data);
- $zupdates = $zupdates->updates;
-
- if (is_array($zupdates) && count($zupdates) > 0) {
- $zupdate_ids = array();
- foreach ($zupdates as $zupdate) {
- $zupdate_ids[] = $wpdb->escape($zupdate->hashcode);
- }
- $existing_ids = $wpdb->get_col("
- SELECT zupdate_hash
- FROM $wpdb->cfzt
- WHERE zupdate_hash
- IN ('".implode("', '", $zupdate_ids)."')
- ");
- $new_zupdates = array();
- foreach ($zupdates as $zupdate_data) {
- if (!empty($zupdate_data->media)) {
- $zupdate_data->media = serialize($zupdate_data->media);
- }
- else {
- $zupdate_data->media = "";
- }
- if (!$existing_ids || !in_array($zupdate_data->hashcode, $existing_ids)) {
- $zupdate = new cfzt_zupdate(
- $zupdate_data->hashcode
- , $zupdate_data->type
- , $zupdate_data->tags
- , $zupdate_data->timestamp
- , $zupdate_data->description
- , $zupdate_data->user->name
- , $zupdate_data->media
- , $zupdate_data->embedCode
- , $zupdate_data->zannelurl
- );
- // make sure we haven't downloaded someone else's updates - happens sometimes due to Zannel hiccups
- if (strtolower($zupdate_data->user->name) == strtolower($cfzt->zannel_username)) {
- $new_zupdates[] = $zupdate;
- }
- }
- }
- foreach ($new_zupdates as $zupdate) {
- $zupdate->add();
- }
- }
- cfzt_reset_zupdate_checking($hash, time());
- }
-
- function cfzt_reset_zupdate_checking($hash = '', $time = 0) {
- if (!current_user_can('manage_options')) {
- return;
- }
- update_option('cfzt_zupdate_hash', $hash);
- update_option('cfzt_last_zupdate_download', $time);
- update_option('cfzt_doing_zupdate_download', '0');
- }
-
- function cfzt_notify_zannel($post_id) {
- global $cfzt;
- $cfzt->do_blog_post_zupdate($post_id);
- }
- add_action('publish_post', 'cfzt_notify_zannel', 99);
-
- function cfzt_sidebar_zupdates() {
- global $wpdb, $cfzt;
- if ($cfzt->exclude_reply_zupdates) {
- $where = "AND zupdate_description NOT LIKE '@%' ";
- }
- else {
- $where = '';
- }
- $zupdates = $wpdb->get_results("
- SELECT *
- FROM $wpdb->cfzt
- WHERE zupdate_description NOT LIKE '$cfzt->zupdate_prefix%'
- $where
- GROUP BY id
- ORDER BY zupdate_timestamp DESC
- LIMIT $cfzt->sidebar_zupdate_count
- ");
- $output = '<div class="cfzt_zupdates">'."\n"
- .' <ul>'."\n";
- if (count($zupdates) > 0) {
- foreach ($zupdates as $zupdate) {
- $output .= ' <li>'.cfzt_zupdate_display($zupdate).'</li>'."\n";
- }
- }
- else {
- $output .= ' <li>'.__('No Updates available at the moment.', 'zannel-tools').'</li>'."\n";
- }
- if (!empty($cfzt->zannel_username)) {
- $output .= ' <li class="cfzt_more_updates"><a href="'.cfzt_profile_url($cfzt->zannel_username).'">More Updates...</a></li>'."\n";
- }
- $output .= '</ul>';
- if ($cfzt->zupdate_from_sidebar == '1' && !empty($cfzt->zannel_username) && !empty($cfzt->zannel_password)) {
- $output .= cfzt_zupdate_form('input', 'onsubmit="cfztPostZupdate(); return false;"');
- $output .= ' <p id="cfzt_zupdate_posted_msg">'.__('Posting Update...', 'zannel-tools').'</p>';
- }
- if ($cfzt->give_cfzt_credit == '1') {
- $output .= '<p class="cfzt_credit">Powered by <a href="http://zannel.com">Zannel Tools</a>.</p>';
- }
- $output .= '</div>';
- print($output);
- }
-
- function cfzt_latest_zupdate() {
- global $wpdb, $cfzt;
- $zupdates = $wpdb->get_results("
- SELECT *
- FROM $wpdb->cfzt
- WHERE zupdate_description NOT LIKE '$cfzt->zupdate_prefix%'
- GROUP BY id
- ORDER BY zupdate_timestamp DESC
- LIMIT 1
- ");
- if (count($zupdates) == 1) {
- foreach ($zupdates as $zupdate) {
- $output = cfzt_zupdate_display($zupdate);
- }
- }
- else {
- $output = __('No Updates available at the moment.', 'zannel-tools');
- }
- print($output);
- }
-
- function cfzt_zupdate_display($zupdate, $time = 'relative') {
- global $cfzt;
- $text = cfzt_make_clickable(wp_specialchars($zupdate->zupdate_description)).' ';
- switch ($time) {
- case 'relative':
- $time_display = cfzt_relativeTime($zupdate->zupdate_timestamp, 3);
- break;
- case 'absolute':
- $time_display = '#';
- break;
- }
- switch (strtolower($zupdate->zupdate_type)) {
- case 'text':
- $output = $text.' <a href="'.$zupdate->zupdate_url.'">'.$time_display.'</a>';
- break;
- case 'image':
- $media = unserialize($zupdate->zupdate_media);
- $output = '<a href="'.$zupdate->zupdate_url.'"><span class="zannel_thumb"><img src="'.$media->medium.'"/></span></a> '.$text.'<a href="'.$zupdate->zupdate_url.'">'.$time_display.'</a>';
- break;
- case 'video':
- $media = unserialize($zupdate->zupdate_media);
- $output = '<a href="'.$zupdate->zupdate_url.'"><span class="zannel_thumb"><img src="'.$media->medium.'"/></span></a> '.$text.'<a href="'.$zupdate->zupdate_url.'">'.$time_display.'</a>';
- break;
- }
- return $output;
- }
-
- function cfzt_make_clickable($zupdate) {
- $zupdate .= ' ';
- $zupdate = preg_replace_callback(
- '/@([a-zA-Z0-9_]{1,15})([) ])/'
- , create_function(
- '$matches'
- , 'return cfzt_profile_link($matches[1], \'@\', $matches[2]);'
- )
- , $zupdate
- );
- $zupdate = preg_replace_callback(
- '/\#([a-zA-Z0-9_]{1,15}) /'
- , create_function(
- '$matches'
- , 'return cfzt_hashtag_link($matches[1], \'#\', \' \');'
- )
- , $zupdate
- );
-
- if (function_exists('make_chunky')) {
- return make_chunky($zupdate);
- }
- else {
- return make_clickable($zupdate);
- }
- }
-
- function cfzt_zupdate_form($type = 'input', $extra = '') {
- $output = '';
- if (current_user_can('publish_posts')) {
- $output .= '
- <form action="'.get_bloginfo('wpurl').'/index.php" method="post" id="cfzt_zupdate_form" '.$extra.'>
- <fieldset>
- ';
- switch ($type) {
- case 'input':
- $output .= '
- <p><input type="text" size="20" maxlength="255" id="cfzt_zupdate_text" name="cfzt_zupdate_text" onkeyup="cfztCharCount();" /></p>
- <input type="hidden" name="cfzt_action" value="cfzt_post_zupdate_sidebar" />
- <script type="text/javascript">
- //<![CDATA[
- function cfztCharCount() {
- var count = document.getElementById("cfzt_zupdate_text").value.length;
- if (count > 0) {
- document.getElementById("cfzt_char_count").innerHTML = 255 - count;
- }
- else {
- document.getElementById("cfzt_char_count").innerHTML = "";
- }
- }
- setTimeout("cfztCharCount();", 500);
- document.getElementById("cfzt_zupdate_form").setAttribute("autocomplete", "off");
- //]]>
- </script>
- ';
- break;
- case 'textarea':
- $output .= '
- <p><textarea type="text" cols="60" rows="5" maxlength="255" id="cfzt_zupdate_text" name="cfzt_zupdate_text" onkeyup="cfztCharCount();"></textarea></p>
- <input type="hidden" name="cfzt_action" value="cfzt_post_zupdate_admin" />
- <script type="text/javascript">
- //<![CDATA[
- function cfztCharCount() {
- var count = document.getElementById("cfzt_zupdate_text").value.length;
- if (count > 0) {
- document.getElementById("cfzt_char_count").innerHTML = (255 - count) + "'.__(' characters remaining', 'zannel-tools').'";
- }
- else {
- document.getElementById("cfzt_char_count").innerHTML = "";
- }
- }
- setTimeout("cfztCharCount();", 500);
- document.getElementById("cfzt_zupdate_form").setAttribute("autocomplete", "off");
- //]]>
- </script>
- ';
- break;
- }
- $output .= '
- <p>
- <input type="submit" id="cfzt_zupdate_submit" name="cfzt_zupdate_submit" value="'.__('Post Update!', 'zannel-tools').'" />
- <span id="cfzt_char_count"></span>
- </p>
- <div class="clear"></div>
- </fieldset>
- </form>
- ';
- }
- return $output;
- }
-
- function cfzt_widget_init() {
- if (!function_exists('register_sidebar_widget')) {
- return;
- }
- function cfzt_widget($args) {
- extract($args);
- $options = get_option('cfzt_widget');
- $title = $options['title'];
- if (empty($title)) {
- }
- echo $before_widget . $before_title . $title . $after_title;
- cfzt_sidebar_zupdates();
- echo $after_widget;
- }
- register_sidebar_widget(array(__('Zannel Tools', 'zannel-tools'), 'widgets'), 'cfzt_widget');
-
- function cfzt_widget_control() {
- $options = get_option('cfzt_widget');
- if (!is_array($options)) {
- $options = array(
- 'title' => __("What I'm Doing...", 'zannel-tools')
- );
- }
- if (isset($_POST['cfzt_action']) && $_POST['cfzt_action'] == 'cfzt_update_widget_options') {
- $options['title'] = strip_tags(stripslashes($_POST['cfzt_widget_title']));
- update_option('cfzt_widget', $options);
- // reset checking so that sidebar isn't blank if this is the first time activating
- cfzt_reset_zupdate_checking();
- cfzt_update_zupdates();
- }
-
- // Be sure you format your options to be valid HTML attributes.
- $title = htmlspecialchars($options['title'], ENT_QUOTES);
-
- // Here is our little form segment. Notice that we don't need a
- // complete form. This will be embedded into the existing form.
- print('
- <p style="text-align:right;"><label for="cfzt_widget_title">' . __('Title:') . ' <input style="width: 200px;" id="cfzt_widget_title" name="cfzt_widget_title" type="text" value="'.$title.'" /></label></p>
- <p>'.__('Find additional Zannel Tools options on the <a href="options-general.php?page=zannel-tools.php">Zannel Tools Options page</a>.', 'zannel-tools').'
- <input type="hidden" id="cfzt_action" name="cfzt_action" value="cfzt_update_widget_options" />
- ');
- }
- register_widget_control(array(__('Zannel Tools', 'zannel-tools'), 'widgets'), 'cfzt_widget_control', 300, 100);
-
- }
- add_action('widgets_init', 'cfzt_widget_init');
-
- function cfzt_init() {
- global $wpdb, $cfzt;
- $cfzt = new zannel_tools;
-
- $wpdb->cfzt = $wpdb->prefix.'cfzt_zannel';
-
- $cfzt->get_settings();
- if (($cfzt->last_zupdate_download + $cfzt->zupdate_download_interval()) < time()) {
- add_action('shutdown', 'cfzt_update_zupdates');
- add_action('shutdown', 'cfzt_ping_digests');
- }
- if (is_admin() || $cfzt->zupdate_from_sidebar) {
- switch ($cfzt->js_lib) {
- case 'jquery':
- wp_enqueue_script('jquery');
- break;
- case 'prototype':
- wp_enqueue_script('prototype');
- break;
- }
- }
- }
- add_action('init', 'cfzt_init');
-
- function cfzt_head() {
- global $cfzt;
- if ($cfzt->zupdate_from_sidebar) {
- print('
- <link rel="stylesheet" type="text/css" href="'.get_bloginfo('wpurl').'/index.php?cfzt_action=cfzt_css" />
- <script type="text/javascript" src="'.get_bloginfo('wpurl').'/index.php?cfzt_action=cfzt_js"></script>
- ');
- }
- }
- add_action('wp_head', 'cfzt_head');
-
- function cfzt_head_admin() {
- print('
- <link rel="stylesheet" type="text/css" href="'.get_bloginfo('wpurl').'/index.php?cfzt_action=cfzt_css_admin" />
- <script type="text/javascript" src="'.get_bloginfo('wpurl').'/index.php?cfzt_action=cfzt_js_admin"></script>
- ');
- }
- add_action('admin_head', 'cfzt_head_admin');
-
- function cfzt_request_handler() {
- global $wpdb, $cfzt;
- if (!empty($_GET['cfzt_action'])) {
- switch($_GET['cfzt_action']) {
- case 'cfzt_update_zupdates':
- cfzt_update_zupdates();
- wp_redirect(get_bloginfo('wpurl').'/wp-admin/options-general.php?page=zannel-tools.php&zupdates-updated=true');
- die();
- break;
- case 'cfzt_reset_zupdate_checking':
- cfzt_reset_zupdate_checking();
- wp_redirect(get_bloginfo('wpurl').'/wp-admin/options-general.php?page=zannel-tools.php&zupdate-checking-reset=true');
- die();
- break;
- case 'cfzt_js':
- remove_action('shutdown', 'cfzt_ping_digests');
- header("Content-type: text/javascript");
- switch ($cfzt->js_lib) {
- case 'jquery':
- ?>
- function cfztPostZupdate() {
- var zupdate_field = jQuery('#cfzt_zupdate_text');
- var zupdate_text = zupdate_field.val();
- if (zupdate_text == '') {
- return;
- }
- var zupdate_msg = jQuery("#cfzt_zupdate_posted_msg");
- jQuery.post(
- "<?php bloginfo('wpurl'); ?>/index.php"
- , {
- cfzt_action: "cfzt_post_zupdate_sidebar"
- , cfzt_zupdate_text: zupdate_text
- }
- , function(data) {
- zupdate_msg.html(data);
- cfztSetReset();
- }
- );
- zupdate_field.val('').focus();
- jQuery('#cfzt_char_count').html('');
- jQuery("#cfzt_zupdate_posted_msg").show();
- }
- function cfztSetReset() {
- setTimeout('cfztReset();', 2000);
- }
- function cfztReset() {
- jQuery('#cfzt_zupdate_posted_msg').hide();
- }
- <?php
- break;
- case 'prototype':
- ?>
- function cfztPostZupdate() {
- var zupdate_field = $('cfzt_zupdate_text');
- var zupdate_text = zupdate_field.value;
- if (zupdate_text == '') {
- return;
- }
- var zupdate_msg = $("cfzt_zupdate_posted_msg");
- var cfztAjax = new Ajax.Updater(
- zupdate_msg,
- "<?php bloginfo('wpurl'); ?>/index.php",
- {
- method: "post",
- parameters: "cfzt_action=cfzt_post_zupdate_sidebar&cfzt_zupdate_text=" + zupdate_text,
- onComplete: cfztSetReset
- }
- );
- zupdate_field.value = '';
- zupdate_field.focus();
- $('cfzt_char_count').innerHTML = '';
- zupdate_msg.style.display = 'block';
- }
- function cfztSetReset() {
- setTimeout('cfztReset();', 2000);
- }
- function cfztReset() {
- $('cfzt_zupdate_posted_msg').style.display = 'none';
- }
- <?php
- break;
- }
- die();
- break;
- case 'cfzt_css':
- remove_action('shutdown', 'cfzt_ping_digests');
- header("Content-Type: text/css");
- ?>
- #cfzt_zupdate_form {
- margin: 0;
- padding: 5px 0;
- }
- #cfzt_zupdate_form fieldset {
- border: 0;
- }
- #cfzt_zupdate_form fieldset #cfzt_zupdate_submit {
- float: right;
- margin-right: 10px;
- }
- #cfzt_zupdate_form fieldset #cfzt_char_count {
- color: #666;
- }
- #cfzt_zupdate_posted_msg {
- background: #ffc;
- display: none;
- margin: 0 0 5px 0;
- padding: 5px;
- }
- #cfzt_zupdate_form div.clear {
- clear: both;
- float: none;
- }
- <?php
- die();
- break;
- case 'cfzt_js_admin':
- remove_action('shutdown', 'cfzt_ping_digests');
- header("Content-Type: text/javascript");
- switch ($cfzt->js_lib) {
- case 'jquery':
- ?>
- function cfztTestLogin() {
- var result = jQuery('#cfzt_login_test_result');
- result.show().addClass('cfzt_login_result_wait').html('<?php _e('Testing...', 'zannel-tools'); ?>');
- jQuery.post(
- "<?php bloginfo('wpurl'); ?>/index.php"
- , {
- cfzt_action: "cfzt_login_test"
- , cfzt_zannel_username: jQuery('#cfzt_zannel_username').val()
- , cfzt_zannel_password: jQuery('#cfzt_zannel_password').val()
- }
- , function(data) {
- result.html(data).removeClass('cfzt_login_result_wait');
- setTimeout('cfztTestLoginResult();', 5000);
- }
- );
- };
-
- function cfztTestLoginResult() {
- jQuery('#cfzt_login_test_result').fadeOut('slow');
- };
-
- (function($){
-
- jQuery.fn.timepicker = function(){
-
- var hrs = new Array();
- for(var h = 1; h <= 12; hrs.push(h++));
-
- var mins = new Array();
- for(var m = 0; m < 60; mins.push(m++));
-
- var ap = new Array('am', 'pm');
-
- function pad(n) {
- n = n.toString();
- return n.length == 1 ? '0' + n : n;
- }
-
- this.each(function() {
- var v = $(this).val();
- if (!v) v = new Date();
-
- var d = new Date(v);
- var h = d.getHours();
- var m = d.getMinutes();
- var p = (h >= 12) ? "pm" : "am";
- h = (h > 12) ? h - 12 : h;
-
- var output = '';
-
- output += '<select id="h_' + this.id + '" class="timepicker">';
- for (var hr in hrs){
- output += '<option value="' + pad(hrs[hr]) + '"';
- if(parseInt(hrs[hr],10) == h || (parseInt(hrs[hr],10) == 12 && h == 0)) {
- output += ' selected';
- }
- output += '>' + pad(hrs[hr]) + '</option>';
- }
- output += '</select>';
-
- output += '<select id="m_' + this.id + '" class="timepicker">';
- for (var mn in mins){
- output += '<option value="' + pad(mins[mn]) + '"';
- if(parseInt(mins[mn],10) == m) output += ' selected';
- output += '>' + pad(mins[mn]) + '</option>';
- }
- output += '</select>';
-
- output += '<select id="p_' + this.id + '" class="timepicker">';
- for(var pp in ap){
- output += '<option value="' + ap[pp] + '"';
- if(ap[pp] == p) output += ' selected';
- output += '>' + ap[pp] + '</option>';
- }
- output += '</select>';
-
- $(this).after(output);
-
- var field = this;
- $(this).siblings('select.timepicker').change(function() {
- var h = parseInt(jQuery('#h_'+field.id).val(),10);
- var m = parseInt($('#m_' + field.id).val(),10);
- var p = $('#p_' + field.id).val();
-
- if (p == "am") {
- if (h == 12) {
- h = 0;
- }
- } else if (p == "pm") {
- if (h < 12) {
- h += 12;
- }
- }
-
- var d = new Date();
- d.setHours(h);
- d.setMinutes(m);
-
- $(field).val(d.toUTCString());
- }).change();
-
- });
-
- return this;
- };
-
- jQuery.fn.daypicker = function() {
-
- var days = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
-
- this.each(function() {
- var v = $(this).val();
- if (!v) v = 0;
- v = parseInt(v,10);
-
- var output = "";
- output += '<select id="d_' + this.id + '" class="daypicker">';
- for (var i = 0; i < days.length; i++) {
- output += '<option value="' + i + '"';
- if (v == i) output += ' selected';
- output += '>' + days[i] + '</option>';
- }
- output += '</select>';
-
- $(this).after(output);
-
- var field = this;
- $(this).siblings('select.daypicker').change(function() {
- $(field).val( $(this).val() );
- }).change();
-
- });
-
- };
-
- jQuery.fn.forceToggleClass = function(classNames, bOn) {
- return this.each(function() {
- jQuery(this)[ bOn ? "addClass" : "removeClass" ](classNames);
- });
- };
-
- })(jQuery);
-
- jQuery(function() {
-
- // add in the time and day selects
- jQuery('form#cfzt_zanneltools input.time').timepicker();
- jQuery('form#cfzt_zanneltools input.day').daypicker();
-
- // togglers
- jQuery('.time_toggle .toggler').change(function() {
- var theSelect = jQuery(this);
- theSelect.parent('.time_toggle').forceToggleClass('active', theSelect.val() === "1");
- }).change();
-
- });
- <?php
- break;
- case 'prototype':
- ?>
- function cfztTestLogin() {
- var username = $('cfzt_zannel_username').value;
- var password = $('cfzt_zannel_password').value;
- var result = $('cfzt_login_test_result');
- result.className = 'cfzt_login_result_wait';
- result.innerHTML = '<?php _e('Testing...', 'zannel-tools'); ?>';
- var cfztAjax = new Ajax.Updater(
- result,
- "<?php bloginfo('wpurl'); ?>/index.php",
- {
- method: "post",
- parameters: "cfzt_action=cfzt_login_test&cfzt_zannel_username=" + username + "&cfzt_zannel_password=" + password,
- onComplete: cfztTestLoginResult
- }
- );
- }
- function cfztTestLoginResult() {
- $('cfzt_login_test_result').className = 'cfzt_login_result';
- Fat.fade_element('cfzt_login_test_result');
- }
- <?php
- break;
- }
- die();
- break;
- case 'cfzt_css_admin':
- remove_action('shutdown', 'cfzt_ping_digests');
- header("Content-Type: text/css");
- ?>
- #cfzt_zupdate_form {
- margin: 0;
- padding: 5px 0;
- }
- #cfzt_zupdate_form fieldset {
- border: 0;
- }
- #cfzt_zupdate_form fieldset textarea {
- width: 95%;
- }
- #cfzt_zupdate_form fieldset #cfzt_zupdate_submit {
- float: right;
- margin-right: 50px;
- }
- #cfzt_zupdate_form fieldset #cfzt_char_count {
- color: #666;
- }
- #ak_readme {
- height: 300px;
- width: 95%;
- }
- #cfzt_zanneltools .options {
- overflow: hidden;
- border: none;
- }
- #cfzt_zanneltools .option {
- overflow: hidden;
- border-bottom: dashed 1px #ccc;
- padding-bottom: 9px;
- padding-top: 9px;
- }
- #cfzt_zanneltools .option label {
- display: block;
- float: left;
- width: 200px;
- margin-right: 24px;
- text-align: right;
- }
- #cfzt_zanneltools .option span {
- display: block;
- float: left;
- margin-left: 230px;
- margin-top: 6px;
- clear: left;
- }
- #cfzt_zanneltools select,
- #cfzt_zanneltools input {
- float: left;
- display: block;
- margin-right: 6px;
- }
- #cfzt_zanneltools p.submit {
- overflow: hidden;
- }
- #cfzt_zanneltools .option span {
- color: #666;
- display: block;
- }
- #cfzt_zanneltools #cfzt_login_test_result {
- display: inline;
- padding: 3px;
- }
- #cfzt_zanneltools fieldset.options .option span.cfzt_login_result_wait {
- background: #ffc;
- }
- #cfzt_zanneltools fieldset.options .option span.cfzt_login_result {
- background: #CFEBF7;
- color: #000;
- }
- #cfzt_zanneltools .timepicker,
- #cfzt_zanneltools .daypicker {
- display: none;
- }
- #cfzt_zanneltools .active .timepicker,
- #cfzt_zanneltools .active .daypicker {
- display: block
- }
- fieldset.experimental {
- border: 2px solid #900;
- padding: 10px;
- }
- fieldset.experimental legend {
- color: #900;
- font-weight: bold;
- }
- <?php
- die();
- break;
- }
- }
- if (!empty($_POST['cfzt_action'])) {
- switch($_POST['cfzt_action']) {
- case 'cfzt_update_settings':
- $cfzt->populate_settings();
- $cfzt->update_settings();
- wp_redirect(get_bloginfo('wpurl').'/wp-admin/options-general.php?page=zannel-tools.php&updated=true');
- die();
- break;
- case 'cfzt_post_zupdate_sidebar':
- if (!empty($_POST['cfzt_zupdate_text']) && current_user_can('publish_posts')) {
- $zupdate = new cfzt_zupdate();
- $zupdate->zupdate_description = stripslashes($_POST['cfzt_zupdate_text']);
- if ($cfzt->do_zupdate($zupdate)) {
- die(__('Update posted.', 'zannel-tools'));
- }
- else {
- die(__('Update post failed.', 'zannel-tools'));
- }
- }
- break;
- case 'cfzt_post_zupdate_admin':
- if (!empty($_POST['cfzt_zupdate_text']) && current_user_can('publish_posts')) {
- $zupdate = new cfzt_zupdate();
- $zupdate->zupdate_description = stripslashes($_POST['cfzt_zupdate_text']);
- if ($cfzt->do_zupdate($zupdate)) {
- wp_redirect(get_bloginfo('wpurl').'/wp-admin/post-new.php?page=zannel-tools.php&zupdate-posted=true');
- }
- else {
- wp_die(__('Oops, your Update was not posted. Please check your username and password and that Zannel is up and running happily.', 'zannel-tools'));
- }
- die();
- }
- break;
- case 'cfzt_login_test':
- $test = @cfzt_login_test(
- @stripslashes($_POST['cfzt_zannel_username'])
- , @stripslashes($_POST['cfzt_zannel_password'])
- );
- die(__($test, 'zannel-tools'));
- break;
- }
- }
- }
- add_action('init', 'cfzt_request_handler', 10);
-
- function cfzt_admin_zupdate_form() {
- global $cfzt;
- if ( $_GET['zupdate-posted'] ) {
- print('
- <div id="message" class="updated fade">
- <p>'.__('Update posted.', 'zannel-tools').'</p>
- </div>
- ');
- }
- print('
- <div class="wrap" id="cfzt_write_zupdate">
- ');
- if (empty($cfzt->zannel_username) || empty($cfzt->zannel_password)) {
- print('
- <p>Please enter your <a href="http://zannel.com">Zannel</a> account information in your <a href="options-general.php?page=zannel-tools.php">Zannel Tools Options</a>.</p>
- ');
- }
- else {
- print('
- <h2>'.__('Write Update', 'zannel-tools').'</h2>
- <p>This will create a new \'Update\' in <a href="http://zannel.com">Zannel</a> using the account information in your <a href="options-general.php?page=zannel-tools.php">Zannel Tools Options</a>.</p>
- '.cfzt_zupdate_form('textarea').'
- ');
- }
- print('
- </div>
- ');
- }
-
- function cfzt_options_form() {
- global $wpdb, $cfzt;
-
- $categories = get_categories('hide_empty=0');
- $cat_options = '';
- foreach ($categories as $category) {
- if ($category->term_id == $cfzt->blog_post_category) {
- $selected = 'selected="selected"';
- }
- else {
- $selected = '';
- }
- $cat_options .= "\n\t<option value='$category->term_id' $selected>$category->name</option>";
- }
-
- $authors = get_users_of_blog();
- $author_options = '';
- foreach ($authors as $user) {
- $usero = new WP_User($user->user_id);
- $author = $usero->data;
- // Only list users who are allowed to publish
- if (! $usero->has_cap('publish_posts')) {
- continue;
- }
- if ($author->ID == $cfzt->blog_post_author) {
- $selected = 'selected="selected"';
- }
- else {
- $selected = '';
- }
- $author_options .= "\n\t<option value='$author->ID' $selected>$author->user_nicename</option>";
- }
-
- $js_libs = array(
- 'jquery' => 'jQuery'
- , 'prototype' => 'Prototype'
- );
- $js_lib_options = '';
- foreach ($js_libs as $js_lib => $js_lib_display) {
- if ($js_lib == $cfzt->js_lib) {
- $selected = 'selected="selected"';
- }
- else {
- $selected = '';
- }
- $js_lib_options .= "\n\t<option value='$js_lib' $selected>$js_lib_display</option>";
- }
- $digest_zupdate_orders = array(
- 'ASC' => 'Oldest first (Chronological order)'
- , 'DESC' => 'Newest first (Reverse-chronological order)'
- );
- $digest_zupdate_order_options = '';
- foreach ($digest_zupdate_orders as $digest_zupdate_order => $digest_zupdate_order_display) {
- if ($digest_zupdate_order == $cfzt->digest_zupdate_order) {
- $selected = 'selected="selected"';
- }
- else {
- $selected = '';
- }
- $digest_zupdate_order_options .= "\n\t<option value='$digest_zupdate_order' $selected>$digest_zupdate_order_display</option>";
- }
- $yes_no = array(
- 'create_blog_posts'
- , 'create_digest'
- , 'create_digest_weekly'
- , 'notify_zannel'
- , 'notify_zannel_default'
- , 'zupdate_from_sidebar'
- , 'give_cfzt_credit'
- , 'exclude_reply_zupdates'
- );
- foreach ($yes_no as $key) {
- $var = $key.'_options';
- if ($cfzt->$key == '0') {
- $$var = '
- <option value="0" selected="selected">'.__('No', 'zannel-tools').'</option>
- <option value="1">'.__('Yes', 'zannel-tools').'</option>
- ';
- }
- else {
- $$var = '
- <option value="0">'.__('No', 'zannel-tools').'</option>
- <option value="1" selected="selected">'.__('Yes', 'zannel-tools').'</option>
- ';
- }
- }
- if ( $_GET['zupdates-updated'] ) {
- print('
- <div id="message" class="updated fade">
- <p>'.__('Zannel Updates updated.', 'zannel-tools').'</p>
- </div>
- ');
- }
- if ( $_GET['zupdate-checking-reset'] ) {
- print('
- <div id="message" class="updated fade">
- <p>'.__('Update checking has been reset.', 'zannel-tools').'</p>
- </div>
- ');
- }
- print('
- <div class="wrap" id="cfzt_options_page">
- <h2>'.__('Zannel Tools Options', 'zannel-tools').'</h2>
- <form id="cfzt_zanneltools" name="cfzt_zanneltools" action="'.get_bloginfo('wpurl').'/wp-admin/options-general.php" method="post">
- <input type="hidden" name="cfzt_action" value="cfzt_update_settings" />
- <fieldset class="options">
- <div class="option">
- <label for="cfzt_zannel_username">'.__('Zannel Username', 'zannel-tools').'/'.__('Password', 'zannel-tools').'</label>
- <input type="text" size="25" name="cfzt_zannel_username" id="cfzt_zannel_username" value="'.$cfzt->zannel_username.'" autocomplete="off" />
- <input type="password" size="25" name="cfzt_zannel_password" id="cfzt_zannel_password" value="'.$cfzt->zannel_password.'" autocomplete="off" />
- <input type="button" name="cfzt_login_test" id="cfzt_login_test" value="'.__('Test Login Info', 'zannel-tools').'" onclick="cfztTestLogin(); return false;" />
- <span id="cfzt_login_test_result"></span>
- </div>
- <div class="option">
- <label for="cfzt_notify_zannel">'.__('Enable option to create a Zannel Update when you post in your blog?', 'zannel-tools').'</label>
- <select name="cfzt_notify_zannel" id="cfzt_notify_zannel">'.$notify_zannel_options.'</select>
- </div>
- <div class="option">
- <label for="cfzt_notify_zannel_default">'.__('Set this on by default?', 'zannel-tools').'</label>
- <select name="cfzt_notify_zannel_default" id="cfzt_notify_zannel_default">'.$notify_za…
Large files files are truncated, but you can click here to view the full file