[4314] | 1 | <?php |
---|
| 2 | if (defined('PHPWG_ROOT_PATH')) return; /* Avoid direct usage under Piwigo */ |
---|
| 3 | if (!defined('PWGP_NAME')) return; /* Avoid unpredicted access */ |
---|
| 4 | |
---|
| 5 | if (!function_exists('pwg_get_contents')) include 'PiwigoPress_get.php'; |
---|
| 6 | |
---|
| 7 | if(!class_exists('PiwigoPress_Admin')){ |
---|
| 8 | class PiwigoPress_Admin { |
---|
| 9 | function PiwigoPress_Admin(){ |
---|
| 10 | //add_action("admin_menu", array($this, "getAdminMenu")); |
---|
| 11 | add_action("admin_print_scripts", array(&$this, 'head')); |
---|
| 12 | add_filter( 'media_buttons_context', array(&$this,'add_button'), 99 ); |
---|
| 13 | add_filter( 'media_upload_tabs', array(&$this, 'add_tab'), 99); |
---|
| 14 | add_filter( 'media_upload_piwigo', array(&$this, 'add_Piwigo'), 99); |
---|
| 15 | add_filter( 'media_upload_result', array(&$this, 'add_Piwigo'), 99); |
---|
| 16 | add_filter( 'media_upload_criteria', array(&$this, 'add_Piwigo'), 99); |
---|
| 17 | add_filter( 'media_upload_select', array(&$this, 'add_Piwigo'), 99); |
---|
| 18 | $this->pwg_options = 'PiwigoPress_Admin'; |
---|
| 19 | add_option($this->pwg_options, serialize(array())); |
---|
| 20 | $this->gallery = unserialize(get_option($this->pwg_options)); |
---|
| 21 | $this->previous = $this->gallery; // Previous is not currently used |
---|
| 22 | $this->get_request(); |
---|
| 23 | $this->update(); |
---|
| 24 | update_option($this->pwg_options, serialize($this->gallery)); |
---|
| 25 | $piwigo = empty($this->gallery['piwigo']) ? '' : $this->gallery['piwigo']; |
---|
| 26 | $piwigo_url = 'http://' . $_SERVER['HTTP_HOST'] . '/' . $piwigo ; |
---|
| 27 | if (!empty($this->gallery['external'])) $piwigo_url = $this->gallery['external']; |
---|
| 28 | if (substr($piwigo_url,-1)!='/') $piwigo_url .= '/'; |
---|
| 29 | $this->piwigo_url = $piwigo_url; |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | #add Piwigo button on editor-toolbar |
---|
| 33 | function add_button($context=''){ |
---|
| 34 | global $post_ID, $temp_ID; |
---|
| 35 | $_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID); |
---|
| 36 | $this->post_id = $_ID; |
---|
| 37 | $iframe_src = 'media-upload.php?post_id='.$_ID.'&type=piwigo&TB_iframe=true'; |
---|
| 38 | $title = __('Add Some Pictures From Piwigo'); |
---|
| 39 | $out = '<a href="'.$iframe_src.'" id="add_Piwigo_image" class="thickbox" title="' |
---|
| 40 | .$title.'"><img src="'.PWGA_PATH.'images/piwigo.png"/></a>'; |
---|
| 41 | $context.=$out; |
---|
| 42 | return $context; |
---|
| 43 | } |
---|
| 44 | function add_tab($tabs) { |
---|
| 45 | global $wpdb; /* Need for recent thumbnail access */ |
---|
| 46 | if($_REQUEST['type'] != 'piwigo') return $tabs; |
---|
| 47 | $response = pwg_get_contents( $this->piwigo_url |
---|
| 48 | . 'ws.php?method=pwg.categories.getList&format=php'); |
---|
| 49 | $this->gallery['categories'] = unserialize($response); |
---|
| 50 | $this->gallery['images']['stat'] = $this->gallery['categories']['stat']; |
---|
| 51 | if ($this->gallery['categories']['stat'] == 'ok') { |
---|
| 52 | $options = ''; |
---|
| 53 | $number = empty($this->gallery['number']) ? 10 : intval($this->gallery['number']); |
---|
| 54 | $options .= '&per_page=' . $number; |
---|
| 55 | if (!empty($this->gallery['category'])) $options .= '&cat_id=' . intval($this->gallery['category']); |
---|
| 56 | $from = empty($this->gallery['from']) ? '12' : intval($this->gallery['from']); |
---|
| 57 | $r = (array) $wpdb->get_results('SELECT date_sub( date( now( ) ) , INTERVAL ' . $from . ' MONTH ) as begin'); |
---|
| 58 | $from = $r[0]->begin; |
---|
| 59 | if (!empty($this->gallery['from'])) $options .= '&f_min_date_created=' . $from; |
---|
| 60 | $response = pwg_get_contents( $this->piwigo_url |
---|
| 61 | . 'ws.php?method=pwg.categories.getImages&format=php' |
---|
| 62 | . $options . '&recursive=true&order=random&f_with_thumbnail=true'); |
---|
| 63 | $this->gallery['images'] = unserialize($response); |
---|
| 64 | } |
---|
| 65 | $tab = (isset($_GET['tab'])) ? strip_tags(stripslashes($_GET['tab'])):'type'; // Default results |
---|
| 66 | if ( $this->gallery['categories']['stat'] != 'ok') $tab = 'select'; // No WS available |
---|
| 67 | if ( $this->gallery['images']['stat'] != 'ok') $tab = 'select'; // No WS available |
---|
| 68 | if ( $tab != 'select' and $this->gallery['images']['result']['images']['count'] == 0 ) $tab = 'criteria'; // No pictures available |
---|
| 69 | if ( $tab != 'select' and count($this->gallery['categories']['result']['categories']) == 0 ) $tab = 'select'; // No categories available |
---|
| 70 | $this->gallery['tab'] = $tab; |
---|
| 71 | if ( $this->gallery['images']['stat'] == 'ok' and $this->gallery['images']['result']['images']['count'] > 0 ) return array( |
---|
| 72 | 'result' => __('Select pictures'), |
---|
| 73 | 'criteria' => __('Your criteria'), |
---|
| 74 | 'select' => __('Select the Piwigo gallery'), |
---|
| 75 | ); |
---|
| 76 | if ( $this->gallery['categories']['stat'] == 'ok' and count($this->gallery['categories']['result']['categories']) > 0 ) return array( |
---|
| 77 | 'criteria' => __('Your criteria'), |
---|
| 78 | 'select' => __('Select the Piwigo gallery'), |
---|
| 79 | ); |
---|
| 80 | else return array( |
---|
| 81 | 'select' => __('Select the Piwigo gallery'), |
---|
| 82 | ); |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | function get_request() { |
---|
| 86 | $this->request = $this->gallery; |
---|
| 87 | foreach($_REQUEST as $key=>$value) { |
---|
| 88 | if(substr($key, 0, 12) == "PiwigoPress_") |
---|
| 89 | $this->request[substr($key, 12)] = trim($value); |
---|
| 90 | } |
---|
| 91 | } |
---|
| 92 | function update(){ |
---|
| 93 | $this->gallery['piwigo'] = strip_tags(stripslashes($this->request['piwigo'])); |
---|
| 94 | $this->gallery['external'] = strip_tags(stripslashes($this->request['external'])); |
---|
| 95 | } |
---|
| 96 | function head() { |
---|
| 97 | ?> |
---|
| 98 | <link href="<?php bloginfo("wpurl"); ?>/wp-content/plugins/piwigopress/css/style.css" type="text/css" rel="stylesheet"/> |
---|
| 99 | <script type="text/javascript" src="<?php bloginfo("wpurl"); ?>/wp-content/plugins/piwigopress/js/scripts.js"></script> |
---|
| 100 | <?php |
---|
| 101 | } |
---|
| 102 | function add_Piwigo() { |
---|
| 103 | return wp_iframe(array($this, "add_PiwigoContent")); |
---|
| 104 | } |
---|
| 105 | function add_PiwigoContent() { |
---|
| 106 | $html = media_upload_header(); |
---|
| 107 | $html .= '<div class="wrapper Piwigo_container">'; |
---|
| 108 | switch ($this->gallery['tab']) { |
---|
| 109 | case 'type': |
---|
| 110 | $html .= $this->add_Piwigo_Select(); |
---|
| 111 | break; |
---|
| 112 | case 'criteria': |
---|
| 113 | $html .= $this->add_Piwigo_Select(); |
---|
| 114 | break; |
---|
| 115 | case 'select': |
---|
| 116 | $html .= $this->add_Piwigo_Select(); |
---|
| 117 | break; |
---|
| 118 | } |
---|
| 119 | $html .= '</div>'; |
---|
| 120 | echo $html; |
---|
| 121 | } |
---|
| 122 | function add_Piwigo_Select() { |
---|
| 123 | $piwigo = (empty($this->gallery['piwigo'])) ? 'piwigo' : $this->gallery['piwigo']; |
---|
| 124 | $external = (empty($this->gallery['external'])) ? '' : $this->gallery['external']; |
---|
| 125 | |
---|
| 126 | $iframe_src = 'media-upload.php?post_id='.$_ID.'&type=piwigo&TB_iframe=true'; |
---|
| 127 | $message = (isset($this->request['sub-url'])) ? __('Configuration saved'):''; |
---|
| 128 | |
---|
| 129 | return '<h3 class="media-title">' |
---|
| 130 | . __('From my Piwigo gallery','pwg') . '</h3>' |
---|
| 131 | . nl2br(__(<<<EOF |
---|
| 132 | Set Piwigo gallery: |
---|
| 133 | - directory, if Piwigo is on the same domain than your blog (relative path from the domain), |
---|
| 134 | - URL, if Piwigo gallery is an external website or another subdomain. |
---|
| 135 | |
---|
| 136 | Remind that only public images with a null privacy level could be collected from there. |
---|
| 137 | Directory is ignored if an URL is provided. |
---|
| 138 | EOF |
---|
| 139 | ,'pwg')) . '<br/><br/>' . $message . '<br/> |
---|
| 140 | <form id="piwigo-form" class="media-upload-form type-form validate" method="post" enctype="multipart/form-data" |
---|
| 141 | action="media-upload.php?post_id=' . $this->post_id . '&type=piwigo&TB_iframe=true"> |
---|
| 142 | <input type="hidden" id="post_id" name="post_id" value="' . $this->post_id . '"/> |
---|
| 143 | <input type="hidden" name="_wpnonce" id="_wpnonce" value="' . wp_create_nonce('media-form') . '"/> |
---|
| 144 | <input type="hidden" name="_wp_http_referer" |
---|
| 145 | value="media-upload.php?post_id=' . $this->post_id . '&type=piwigo&TB_iframe=true"/> |
---|
| 146 | |
---|
| 147 | <p style="text-align:right;"><label for="piwigo">' . __('<strong>Local</strong> directory (if local)','pwg') . ' |
---|
| 148 | <input style="width: 200px;" id="piwigo" name="PiwigoPress_piwigo" type="text" value="' . $piwigo . '" /></label> |
---|
| 149 | </p> |
---|
| 150 | |
---|
| 151 | <p style="text-align:right;"><label for="external">' . __('(or) <strong>External</strong> gallery URL','pwg') . ' |
---|
| 152 | <input style="width: 250px;" id="external" name="PiwigoPress_external" type="text" value="' . $external . '" /></label> |
---|
| 153 | </p> |
---|
| 154 | |
---|
| 155 | <p style="text-align:right;"> |
---|
| 156 | <input type="submit" id="piwigo-submit" value="' . __('Submit','pwg') . '" name="PiwigoPress__sub-url" class="button-primary alignright"> |
---|
| 157 | </p> |
---|
| 158 | |
---|
| 159 | </form>'; |
---|
| 160 | } |
---|
| 161 | } |
---|
| 162 | } |
---|
| 163 | if (!is_object($PWG_Adm)) { |
---|
| 164 | $PWG_Adm = new PiwigoPress_Admin(); |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | /* |
---|
| 168 | function getAdminMenu() { |
---|
| 169 | add_submenu_page("plugins.php", "PiwigoPress", "PiwigoPress", "administrator", basename(__FILE__), array(&$PWG_Adm, "getAdminContent")); |
---|
| 170 | } |
---|
| 171 | */ |
---|
| 172 | |
---|
| 173 | ?> |
---|