private function __construct() { $success = OnePanelDebug::Track('Starting Language Engine'); // Build the hooks array self::SetHooks(); $success->Affirm(); }
/** * * @param $post * @return unknown_type * @todo anything in the html that has dodgy characters in it will make DOM unhappy. * Probably best to hold back errors. */ public static function AutoGenThumbs($post) { $tracker = OnePanelDebug::Track('Trying to autogenerate thumbnails.'); // Wordpress is crazy $post_id = wp_is_post_revision($post); OnePanelDebug::Info('Post id: ' . $post_id); // Create thumbnail module object? OnePanelLib::RequireFileOnce(ONE_PANEL_DIR . '/panel/module.php'); OnePanelLib::RequireFileOnce(ONE_PANEL_DIR . '/panel/feature.php'); OnePanelLib::RequireFileOnce(ONE_PANEL_DIR . '/panel/thumbnails.php'); $thumbnail_feature_object = new Thumbnails(); // Scan the post for images $dom_doc = new DOMDocument(); @$dom_doc->loadHTML($_POST['content']); // Grab the first image $first_image = $dom_doc->getElementsByTagName('img')->item(0); if (is_null($first_image)) { OnePanelDebug::Info('No images found in post'); return true; } // Get the location of the image $src = str_replace('"', '', $first_image->getAttribute('src')); $src = str_replace('\\', '', $src); // Get the real path $src = str_replace(get_option('siteurl'), '', $src); $location = ABSPATH . $src; $location = str_replace('//', '/', $location); // Generate OnePanelDebug::Info('Calling CreateThumbs with ' . $location . ' ' . $post_id); $thumbnail_feature_object->CreateThumbs($location, $post_id, 'All', false); // All done $tracker->Affirm(); return true; }
/** * RequireFileOnce * * Uses OnePanelDebug and runs a require_once on the file path provided. * * @param $file_path * @return boolean */ public static function RequireFileOnce($file_path) { $success = OnePanelDebug::Track('Including file: ' . $file_path); if (file_exists(realpath($file_path))) { require_once realpath($file_path); $success->Affirm(); } else { OnePanelDebug::Error('The file ' . $file_path . ' does not exist'); $success->Fail(); } return true; }
/** * Create Thumbnails * * @param str $source_file * @param int $post_id * @param str $thumb_to_generate * @param bool $overwrite_existing * @return Error string on error, TRUE on success * @todo this function is ridiculous, chop it up */ public function CreateThumbs($source_file, $post_id, $thumb_to_generate, $overwrite_existing = false) { // Debug $success = OnePanelDebug::Track('Creating thumbnails: ' . $thumb_to_generate); // Get WordPress' uploads data $wp_uploads_data = wp_upload_dir(); $upload_directory = $wp_uploads_data['path']; if (is_writable($upload_directory)) { OnePanelDebug::Info('Upload dir is writable.'); // Figure out how many thumbs we are generating $actual_thumbs_to_gen = array(); $config_thumbs = OnePanelConfig::GetThumbnailTypes(); if ($config_thumbs == false) { OnePanelDebug::Info('No additional thumbnail types passed from config.'); } // Set up catch all. if ($thumb_to_generate == 'All') { $actual_thumbs_to_gen[] = 'Thumbnail'; foreach ($config_thumbs as $key => &$thumbnail_type) { $actual_thumbs_to_gen[] = $thumbnail_type->GetCustomField(); } } else { // Just the passed thumbnail type. // TODO check that the passed ttg is in the config $actual_thumbs_to_gen[] = $thumb_to_generate; } // Create the thumbs we need. foreach ($actual_thumbs_to_gen as &$custom_field_name) { // Debug OnePanelDebug::Info('Attempting to build thumbnail for ' . $custom_field_name); // Check for an existing thumb $existing = get_post_meta($post_id, $custom_field_name); if (empty($existing)) { $existing = false; } else { OnePanelDebug::Info('Thumb already exists ' . ($overwrite_existing ? 'attempting overwrite' : 'skipping')); } // Dont do anything if overwrite is off and theres an existing thumb if ($existing != false && $overwrite_existing == false) { continue; } // Dims are set differently for the standard thumbnails if ($custom_field_name == 'Thumbnail') { $default_thumbnail_dims = OnePanelConfig::GetThumbnailSize(); $width = $default_thumbnail_dims['Width']; $height = $default_thumbnail_dims['Height']; } // Get the dims for this thumbnail type and try and resize it foreach ($config_thumbs as $key => &$config_thumb) { if ($config_thumb->GetCustomField() == $custom_field_name) { $width = $config_thumb->GetWidth(); $height = $config_thumb->GetHeight(); } } // Can we create the resized image? OnePanelDebug::Info('Attempting to create thumbnail ' . $source_file . ' ' . $width . 'x' . $height); $new_thumbnail_path = image_resize($source_file, $width, $height, true); // TODO this really shouldnt be here, if this is a html returning function if (is_wp_error($new_thumbnail_path) || $new_thumbnail_path == false) { if (is_wp_error($new_thumbnail_path)) { OnePanelDebug::Error($new_thumbnail_path->get_error_message()); } OnePanelDebug::Error('Unable to create thumbnail, moving to next iteration.'); $error = '<div class="popup_no_results"><div class="module_error_stroke">One Panel could not resize the image for ' . $custom_field_name . '. <a href="javascript:;" onclick="op_admin.Thumbnails.SwitchMode(\'tool\')">Please try another.</a></div></div>'; continue; } else { OnePanelDebug::Info('Thumbnail created successfully with path ' . $new_thumbnail_path); } // Get the url for the one we just created $new_thumbnail_url = str_replace(ABSPATH, get_option('siteurl') . '/', $new_thumbnail_path); // Add the custom field to the post if ($existing && $overwrite_existing == true) { delete_post_meta($post_id, $custom_field_name); } add_post_meta($post_id, $custom_field_name, $new_thumbnail_url); OnePanelDebug::Info('Custom field added with' . $new_thumbnail_url); } // Prepare the return value if (isset($error)) { $return = $error; } else { $return = true; } } else { // Upload path is not writable $return = '<div class="popup_no_results"><div class="module_error_stroke">The image path is not currently writable. Please chmod the directory first.</div></div>'; } $success->Affirm(); return $return; }
/** * FeatureIsEnabled * * Determine whether a feature is enabled. * * @param string $feature_name * @return boolean */ public static function FeatureIsEnabled($feature_name) { $success = OnePanelDebug::Track('Checking if feature [' . $feature_name . '] is enabled'); if (!is_array(self::$features_enabled)) { self::$features_enabled = array(); } if (in_array($feature_name, self::$features_enabled)) { OnePanelDebug::Info('Feature is enabled'); $success->Affirm(); return true; } else { OnePanelDebug::Info('Feature is not enabled'); $success->Affirm(); return false; } }
/** * Data Upgrade Available * * A quick test to see whether the user data is out of date. * * @uses assumes that if opdata[0] exists, so does the data version info * @return bool */ private function DataUpgradeAvailable() { // Debug $track = OnePanelDebug::Track('Checking for possible data upgrades'); // Dont run if there isnt any data. if (empty(self::$operational_data)) { OnePanelDebug::Info('No operational data yet, aborting upgrade attempt.'); $track->Affirm(); return false; } // Check for corruption in the operational data. if (!isset(self::$operational_data[0]['data_version_date'])) { // Throw an error, anomaly detected OnePanelDebug::Error('Checking for upgrades on corrupted data - missing data_version.'); $track->Fail(); return false; } else { // Check the data against the version date constant if (ONE_PANEL_VERSION_DATE > (int) self::$operational_data[0]['data_version_date']) { OnePanelDebug::Info('Upgrade required.'); $track->Affirm(); return true; } else { OnePanelDebug::Info('No upgrade required.'); $track->Affirm(); return false; } } }