Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
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;
 }