/**
  * 
  * @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;
 }
Esempio n. 2
0
 private function __construct()
 {
     $success = OnePanelDebug::Track('Starting Language Engine');
     // Build the hooks array
     self::SetHooks();
     $success->Affirm();
 }
Esempio n. 3
0
 /**
  * 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;
 }
Esempio n. 4
0
 *  TODO consider allowing language terms of One Panel to be editable in future,
 *  the object will need to be started here at that point.
 */
OnePanelLib::RequireFileOnce(ONE_PANEL_DIR . '/language.php');
// Include the config class, and create the OnePanelConfig Object
OnePanelLib::RequireFileOnce(ONE_PANEL_DIR . '/onepanelconfig.php');
OnePanelConfig::Start();
// Include Externals
//OnePanelLib::RequireFileOnce( ONE_PANEL_DIR .'/onepanelexternals.php' );
//OnePanelExternals::AddActions();
// THESE ARE BROKEN
/*
 * Create one of two objects depending on which environment we appear
 * to be using. The OnePanelTheme has methods that should be available to
 * theme developers, but do not need to be present in the backend.
 */
if (is_admin() || OnePanelLib::InAjaxMode()) {
    // Log
    OnePanelDebug::Info('Running non AJAX mode in OnePanel.');
    // Instantiate the OnePanel Object
    OnePanelLib::RequireFileOnce(ONE_PANEL_DIR . '/panel/onepanel.php');
    OnePanel::Start();
} else {
    /*
     * TODO There is no reason to load the OnePanelTheme object if a config file
     * isnt present in the theme folder.
     */
    // Instantiate the OnePanelTheme Object
    OnePanelLib::RequireFileOnce(ONE_PANEL_DIR . '/onepaneltheme.php');
    OnePanelTheme::Start();
}
Esempio n. 5
0
 /**
  * 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;
 }
Esempio n. 6
0
 /**
  * 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;
     }
 }
Esempio n. 7
0
 /**
  * SoftwareUpgradeAvailable
  * 
  * Determines whether a newer version of the software is available for installation
  * 
  * @return bool
  */
 private function SoftwareUpgradeAvailable()
 {
     // Get the data version from the server
     $host_name = 'one-theme.com';
     $host_header = 'Host:updates.one-theme.com';
     $sp = @fsockopen($host_name, '80', $error_no, $error_str, 15);
     if ($sp) {
         fputs($sp, 'GET /new_version.php HTTP/1.1' . "\r\n");
         fputs($sp, $host_header . "\r\n");
         fputs($sp, "Connection:close\r\n\r\n");
         $response = '';
         while (!feof($sp)) {
             $response .= fgets($sp, 128);
         }
         fclose($sp);
         $response = explode("\r\n\r\n", $response);
         // Check for a bad response or set var
         if (!empty($response[1])) {
             $newest_version = $response[1];
         }
     }
     // Make sure we have newest_version
     if (!isset($newest_version)) {
         OnePanelDebug::Error('Could not connect to server for newest version.');
         return false;
     } else {
         // Check newest_version against our version constant
         if ($newest_version > ONE_PANEL_VERSION_DATE) {
             OnePanelDebug::Info('New One Panel version available for download.');
             return true;
         }
     }
     return false;
 }
Esempio n. 8
0
 public static function Shutdown()
 {
     /*
      * Break out of this function if we do not need to run it.
      * This is important when we are not in AJAX mode and the 
      * user is not looking at OnePanel
      * 
      */
     if (!OnePanelLib::InConsole()) {
         return true;
     }
     /*
      * TODO
      * Ive got a feeling that printing <script> tags outside the html tags is a bad idea
      * perhaps this function should only be used as a last ditch attempt to scrape data in
      * the case of a fatal php error and another shutdown function should be run after the
      * plugin has completed whatever hook is being called.
      * 
      */
     // Discern whether a fatal error occured TODO handle non fatals
     $last_error = error_get_last();
     if ($last_error['type'] === E_ERROR || $last_error['type'] === E_USER_ERROR || $last_error['type'] === E_COMPILE_ERROR || $last_error['type'] === E_CORE_ERROR || $last_error['type'] === E_RECOVERABLE_ERROR) {
         // Fail the last entry
         self::FailIncompleteTrackers();
         // Store the log if necessary
         // Stop the clock
         self::$finish_time = microtime(true);
         // Record memory usage
         self::$finish_mu = memory_get_usage();
         // Output the apppropriate data depending on running environment (AJAX or normal)
         echo self::GetRawOutput();
     } else {
         // Stop the clock
         self::$finish_time = microtime(true);
         // Record memory usage
         self::$finish_mu = memory_get_usage();
         // Script completed. Send the jacascript to populate the error console
         if (!OnePanelLib::InAjaxMode()) {
             echo self::GetOutput();
             // TODO, devise a strategy to append the return ajax data with the error console data.
         }
     }
     return true;
 }