Skip to content

Commit 6e25140

Browse files
committed
Fixed all debug warnings
1 parent 2b772cb commit 6e25140

File tree

10 files changed

+53
-39
lines changed

10 files changed

+53
-39
lines changed

Origin.php

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,17 @@ function render_page(){
185185
$selectors = $this->css->get_setting_selectors();
186186
$css_js_function = $this->css->get_js_function();
187187

188-
$updated = ($_POST['action'] == 'save');
188+
$updated = (@$_POST['action'] == 'save');
189189

190190
// Get the current filters
191191
$user = wp_get_current_user();
192-
$user_filters = get_user_meta($user->ID, 'origin_filters', true);
193-
if($user_filters['theme'] != $this->theme_name) unset($user_filters);
194-
if(empty($user_filters)) $user_filters = array('section' => null, 'tag' => null, 'selector' => null);
192+
$user_filters = get_user_meta($user->ID, 'origin_filters', false);
193+
194+
if(empty($user_filters) || @$user_filters['theme'] != $this->theme_name){
195+
$user_filters['section'] = null;
196+
$user_filters['tag'] = null;
197+
$user_filters['selector'] = null;
198+
}
195199

196200
// Start URL is the page we'll start the preview from
197201
if(!empty($_GET['ref'])) $start_url = $_GET['ref'];
@@ -226,6 +230,10 @@ function get_storage_url($sub = ''){
226230
return $upload_dir['baseurl'].'/origin'.(!empty($sub) ? '/'.$sub : '');
227231
}
228232

233+
public function get_config(){
234+
return $this->_config;
235+
}
236+
229237
////////////////////////////////////////////////////////////////////////////
230238
// Action functions (add_action)
231239
////////////////////////////////////////////////////////////////////////////
@@ -335,7 +343,7 @@ function action_admin_bar_menu(){
335343

336344
if(!is_admin() && !is_404()){
337345
$href = add_query_arg(array(
338-
'ref' => 'http://'.$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]
346+
'ref' => urlencode('http://'.$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"])
339347
), $href);
340348
}
341349

@@ -344,22 +352,13 @@ function action_admin_bar_menu(){
344352

345353
list($v) = explode('-', $wp_version, 2);
346354

347-
if(version_compare($v, '3.3', '>=')){
348-
// WP >= 3.3 uses a different admin bar structure
349-
$wp_admin_bar->add_menu(array(
350-
'parent' => 'site-name',
351-
'title' => 'Design',
352-
'href' => $href,
353-
));
354-
}
355-
else{
356-
// Older menu bar has an appearance tab
357-
$wp_admin_bar->add_menu(array(
358-
'parent' => 'appearance',
359-
'title' => 'Design',
360-
'href' => $href,
361-
));
362-
}
355+
$wp_admin_bar->add_menu(array(
356+
// Parent is dependent on WordPress version
357+
'parent' => version_compare($v, '3.3', '>=') ? 'site-name' : 'appearance',
358+
'title' => 'Design',
359+
'id' => 'origin-design',
360+
'href' => $href
361+
));
363362

364363
return $wp_admin_bar;
365364
}

config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
return array(
4+
'mode' => 'dev',
45
'endpoint' => 'http://192.168.1.102:8888/theme',
56
'path' => 'plugins/origin'
67
);

inc/CSS.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function __construct($filename = null){
2626
/**
2727
* Parse a CSS file
2828
*/
29-
function parse(){
29+
function parse($file = null){
3030
if(!empty($this->css_doc)) return $this->css_doc;
3131
if(!class_exists('CSSParser')) require(dirname(__FILE__).'/../externals/css-parser/CSSParser.php');
3232

inc/CSS_Executor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public static function rgba($color, $opacity){
4949
////////////////////////////////////////////////////////////////////////////
5050

5151
public static function css_texture($name, $level){
52+
if($name == '::none' || $level == 0) return 'none';
5253
return 'url('.get_template_directory_uri().'/images/textures/levels/'.$name.'_l'.$level.'.png)';
5354
}
5455

inc/Image.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,13 @@ function get_preset_url($preset, $attachment_id, $filename = 'image.jpg'){
8787
return site_url().'/oim/'.urlencode($preset).'/'.intval($attachment_id).'/'.$filename.'/';
8888
}
8989
else{
90-
// TODO Return an ugly version
90+
// Return an ugly version
91+
return add_query_arg(array(
92+
'om' => 'im_preset',
93+
'resize_preset' => $preset,
94+
'attachment_id' => intval($attachment_id),
95+
'filename' => $filename
96+
), site_url());
9197
}
9298
}
9399

@@ -97,7 +103,7 @@ function get_preset_url($preset, $attachment_id, $filename = 'image.jpg'){
97103
function flush_rewrite_rules(){
98104
$rules = get_option( 'rewrite_rules' );
99105
// Flush the rules
100-
if(count(array_intersect(array_keys(self::$_url_rules) , array_keys($rules))) != count(self::$_url_rules)){
106+
if(!empty($rules) && count(array_intersect(array_keys(self::$_url_rules) , array_keys($rules))) != count(self::$_url_rules)){
101107
// Flush the rules
102108
global $wp_rewrite;
103109
$wp_rewrite->flush_rules();
@@ -149,14 +155,19 @@ function method_preset(){
149155

150156
// Test if the location is valid
151157
exec("$convert -version", $output);
152-
preg_match('/'.preg_quote('Version: ImageMagick ').'([0-9.-]+)/', $output[0], $matches);
153158

154-
// We need at least image magick 6.5
155-
if(isset($matches[1]) && version_compare($matches[1], '6', '>='))
156-
set_site_transient('imagemagick_location', $convert, 86400);
159+
if(!empty($output)){
160+
preg_match('/'.preg_quote('Version: ImageMagick ').'([0-9.-]+)/', $output[0], $matches);
161+
162+
// We need at least image magick 6.5
163+
if(isset($matches[1]) && version_compare($matches[1], '6', '>=')){
164+
$convert = trim($convert);
165+
set_site_transient('imagemagick_location', $convert, 86400);
166+
}
167+
else $convert = null;
168+
}
157169
else $convert = null;
158170
}
159-
$convert = trim($convert);
160171

161172
// Get the base folder of the file
162173
$attachment = wp_get_attachment_metadata($post->ID);
@@ -197,8 +208,8 @@ function method_preset(){
197208
header('Pragma: no-cache');
198209

199210
// Ensure there's nothing waiting in the buffer
200-
ob_clean();
201-
flush();
211+
@ob_clean();
212+
@flush();
202213

203214
// Display the image
204215
readfile($file);

inc/Settings.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function get_sense_values(){
8484
* @return Origin_Type The class setting.
8585
*/
8686
function get_object($section, $setting){
87-
if(empty($this->_objects[$section][$settings])){
87+
if(empty($this->_objects[$section][$setting])){
8888
// Instantiate the settings class
8989
$type = $this->_settings[$section]['settings'][$setting]['type'];
9090
$class = 'Origin_Type_'.ucfirst(strtolower($type));
@@ -112,7 +112,7 @@ function set($section, $name, $value){
112112
}
113113

114114
/**
115-
* Saves Origin's state based on the POST variables.
115+
* Saves Origin's state based on the POST variables. Also creates the CSS file.
116116
*/
117117
function save($input = null){
118118
if($input == null) $input = $_POST;
@@ -129,8 +129,7 @@ function save($input = null){
129129
}
130130

131131
// Create the folder if it doesn't already exist
132-
if(!is_dir(WP_CONTENT_DIR.'/origin')) mkdir(WP_CONTENT_DIR.'/origin', 0777, true);
133-
$filename = WP_CONTENT_DIR.'/origin/'.Origin::single()->theme_name.'.css';
132+
$filename = Origin::single()->css->get_css_path();;
134133

135134
// Save the CSS
136135
file_put_contents($filename, Origin::single()->css->get_css($this->_values));
@@ -201,6 +200,8 @@ function get_score(){
201200
$design = $this->get_sense_values();
202201
$user = wp_get_current_user();
203202

203+
$wp_version = get_bloginfo('version');
204+
204205
$args = array(
205206
'method' => 'POST',
206207
'timeout' => 45,
@@ -221,7 +222,7 @@ function get_score(){
221222
'user-agent' => 'WordPress/' . $wp_version . '; ' . get_site_url()
222223
);
223224

224-
$raw_response = wp_remote_post($this->_config->endpoint.'/'.Origin::single()->theme_name, $args);
225+
$raw_response = wp_remote_post(Origin::single()->get_config()->endpoint.'/'.Origin::single()->theme_name, $args);
225226

226227
if (!is_wp_error($raw_response) && ($raw_response['response']['code'] == 200))
227228
$response = unserialize($raw_response['body']);

inc/types/slider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class="preview-field"
5151

5252
function process_input($input){
5353
// WordPress doesn't seem to like storing booleans, so we use strings.
54-
if($this->settings['is_int']) $this->value = intval($input[$this->form_name]);
54+
if(!empty($this->settings['is_int'])) $this->value = intval($input[$this->form_name]);
5555
else $this->value = floatval($_POST[$this->form_name]);
5656

5757
}

inc/types/type.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function get_setting($name, $default = false){
5959
}
6060

6161
function value(){
62-
return isset($this->value) ? $this->value : $this->settings['default'];
62+
return isset($this->value) ? $this->value : @$this->settings['default'];
6363
}
6464

6565
function set_value($value){

js/preview/executor.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ var originExecutor = {
4949
////////////////////////////////////////////////////////////////////////////
5050

5151
css_texture : function(name, level) {
52+
if(name == '::none' || level == 0) return 'none';
5253
return 'url('+originSettings.templateUrl+'/images/textures/levels/'+name+'_l'+level+'.png)';
5354
},
5455

tpl/admin.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
<legend class="screen-reader-text"><span><?php print $field['#label'] ?></span></legend>
107107

108108
<?php $obj->render_form(); ?>
109-
<?php if($field['description']) : ?><p class="description"><?php print $field['description'] ?></p><?php endif; ?>
109+
<?php if(!empty($field['description'])) : ?><p class="description"><?php print $field['description'] ?></p><?php endif; ?>
110110
</fieldset>
111111
</td>
112112
</tr>

0 commit comments

Comments
 (0)