public function __construct($name, $file_path) { $this->name = $name; if (OnePanelConfig::CheckFileProperty($file_path)) { $this->file_path =& $file_path; } }
public function AddColorPalette(AdsenseColorPalette $palette, $skin_name) { // If debug, check for the existence of the skin if (is_string($skin_name)) { if (OnePanelConfig::UsingDebug()) { $skins =& OnePanelConfig::GetSkins(); if (!array_key_exists($skin_name, $skins)) { die('You are trying to add a color palette for a skin that has not been added.'); } } } else { die('You must pass a valid string name to AddColorPalette'); } $this->palettes[$skin_name] =& $palette; }
public function __construct($identifier, $custom_field) { if (is_string($identifier)) { $this->identifier = $identifier; } else { if (OnePanelConfig::UsingDebug()) { die('You did not specify an identifier for your thumbnail type.'); } } if (is_string($custom_field)) { $this->custom_field = $custom_field; } else { if (OnePanelConfig::UsingDebug()) { die('You did not specify a custom field for your thumbnail type.'); } } }
* OnePanelLib::RequireFileOnce * */ require_once realpath(ONE_PANEL_DIR . '/onepanellib.php'); // Include Installer File OnePanelLib::RequireFileOnce(ONE_PANEL_DIR . '/onepanelinstaller.php'); /* * Include Language File * No need to start it here, it will be started and put into use when required * 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();
protected function RegisterFeature($classname) { // If there isnt a feature in the data with this classname if (!isset($this->features[$classname])) { // Then create it $this->features[$classname] = new $classname(); } // Important! Make sure the garbage collector does't get it. $this->registered_features[] =& $this->features[$classname]; // Set the enabled state of the feature if (OnePanelConfig::FeatureIsEnabled($classname)) { $this->features[$classname]->Enable(); // Enable the feature $this->enabled_features[] = $classname; } else { $this->features[$classname]->Disable(); // Disable the feature } }
public static function GetDetailedChunk($module_name, $feature_name, $chunk_name) { $module =& self::$operational_data[1][$module_name]; if (OnePanelConfig::UsingDebug()) { if ($module == null) { die('The module ' . $module . ' does not exist.'); } } $chunk =& $module->GetDetailedChunk($feature_name, $chunk_name); if ($chunk == null) { $module->BuildChunks(); $chunk =& $module->GetDetailedChunk($feature_name, $chunk_name); } return $chunk; }
public static function CanBeActive() { global $wpdb; // Number of posts? $number_of_posts = OnePanelConfig::GetNumberOfHotConversationPosts(); if (is_null($number_of_posts)) { $number_of_posts = 4; } $sql = 'SELECT pm.meta_value AS file, p.post_title, p.ID FROM ' . DB_NAME . '.' . $wpdb->prefix . 'posts p LEFT JOIN ' . DB_NAME . '.' . $wpdb->prefix . 'postmeta pm on p.ID = pm.post_id WHERE pm.meta_key = "Thumbnail" ORDER BY p.comment_count DESC LIMIT ' . $number_of_posts; $result = mysql_query($sql); if (!$result) { return false; } if (mysql_num_rows($result) < $number_of_posts) { return false; } else { return true; } }
public static function LoadTerms($language_name, $terms_array, $default = null) { if (OnePanelConfig::UsingDebug()) { if (!is_string($language_name)) { die('Language Name must be a string'); } if (!is_array($terms_array)) { die('Language Terms must be an array'); } } self::$data[$language_name] = $terms_array; if (self::$default_language == null) { self::$default_language = $language_name; } elseif ($default == true) { self::$default_language = $language_name; } }
protected function RegisterFeatures() { // Get the name of the default from the config $config_default = OnePanelConfig::GetDefaultHomePageLayout(); if (!isset($this->features['HomePageLayoutFeature'])) { if (!is_object($config_default)) { return false; } $config_default_name = $config_default->GetName(); $feature = new HomePageLayoutFeature(); $this->features['HomePageLayoutFeature'] =& $feature; $feature->SetAvailableLayouts(OnePanelConfig::GetHomePageLayouts()); $feature->SetDefaultLayout($config_default_name); } else { $this->features['HomePageLayoutFeature']->SetAvailableLayouts(OnePanelConfig::GetHomePageLayouts()); // Check for file path changes in the default config layout rectify if we need to. $our_default = $this->features['HomePageLayoutFeature']->GetDefaultLayout(); $config_layouts = OnePanelConfig::GetHomePageLayouts(); $config_equiv = $config_layouts[$our_default->GetName()]; if (!is_object($config_equiv)) { return false; } if ($config_equiv->GetLocation() != $our_default->GetLocation()) { $this->features['HomePageLayoutFeature']->SetDefaultLayout($config_default->GetName()); } } if (OnePanelConfig::FeatureIsEnabled('HomePageLayoutFeature')) { $this->features['HomePageLayoutFeature']->Enable(); // Enable the feature $this->enabled_features[] = 'HomePageLayoutFeature'; } else { $this->features['HomePageLayoutFeature']->Disable(); // Disable the feature } }
/** * 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; } }
/** * Register Features * * A very customised version of this normally simple function * */ public function RegisterFeatures() { $ad_blocks =& OnePanelConfig::GetAdBlocks(); // Dont do anything if they havent added any adblocks to the config if (is_array($ad_blocks)) { foreach ($ad_blocks as $key => &$block) { if (!isset($this->features[self::GetBlockKey($block->GetName())])) { $new_block = new AdBlockFeature(); $new_block_key = self::GetBlockKey($block->GetName()); $new_block->SetTitle($block->GetName()); $new_block->Enable(); $new_block->SetAlternateKey($new_block_key); /* * We don't use a refrence here as the source object will be replaced * after this iteration. */ $this->features[$new_block_key] = $new_block; // We now refrence the permanent object previously created. $this->registered_features[] =& $this->features[$new_block_key]; $this->enabled_features[] = $new_block_key; } else { $the_block_key = self::GetBlockKey($block->GetName()); $the_block =& $this->features[$the_block_key]; // Make sure its enabled $the_block->Enable(); // Garbage collection and enabled state $this->registered_features[] =& $the_block; $this->enabled_features[] = $the_block_key; } // Set up ajax for it add_action('wp_ajax_opcp_' . self::GetBlockKey($block->GetName()) . 'Activate', array($this->features[self::GetBlockKey($block->GetName())], 'Activate')); add_action('wp_ajax_opcp_' . self::GetBlockKey($block->GetName()) . 'Deactivate', array($this->features[self::GetBlockKey($block->GetName())], 'Deactivate')); } } }
public function GetChunk() { if ($this->IsActive()) { if ($this->video_mode == 2) { if (empty($this->youtube_url)) { return; } // TODO need decent return messages. $the_data = FeaturedVideoModule::GetYouTubeVideo($this->youtube_url); // TODO check the url is not empty $the_chunk = ''; if ($the_data['xml_response'] == 'Video not found') { $the_chunk .= '<div id="video-not-found">' . "\n"; $the_chunk .= 'Sorry, the video has been removed.' . "\n"; $the_chunk .= '</div>' . "\n"; } else { $video_size = OnePanelConfig::GetYoutubeVideoSize(); if (!is_array($video_size)) { $video_size['Width'] = 216; $video_size['Height'] = 197; } $the_chunk .= '<div id="featured-video">' . "\n"; $the_chunk .= '<object data="' . $the_data['url'] . '" type="' . $the_data['type'] . '" width="' . $video_size['Width'] . '" height="' . $video_size['Height'] . '">' . "\n"; $the_chunk .= ' <param name="movie" value="' . $the_data['url'] . '"></param>' . "\n"; $the_chunk .= '</object>' . "\n"; $the_chunk .= '</div>' . "\n"; } return $the_chunk; } elseif ($this->video_mode == 3) { if (empty($this->embed_code)) { return; } // TODO need decent return messages. $the_chunk = ''; $the_chunk .= '<div id="featured-video">' . "\n"; $the_chunk .= stripcslashes($this->embed_code); $the_chunk .= '</div>' . "\n"; return $the_chunk; } else { if (OnePanelConfig::UsingDebug()) { return $this->GetInactiveMessage(); } } } }
public function RegisterFeatures() { $highlights = OnePanelConfig::GetHighlights(); if (is_array($highlights)) { foreach ($highlights as $key => &$highlight) { // If the highlight does not already exist in this modules features if (!isset($this->features[self::GetHighlightKey($highlight->GetName())])) { $new_highlight = new HighlightFeature(); $new_highlight_key = self::GetHighlightKey($highlight->GetName()); $new_highlight->SetTitle($highlight->GetName()); $new_highlight->SetSourceType($highlight->GetDefaultSourceType()); $new_highlight->SetContentLimit($highlight->GetContentLimit()); $new_highlight->SetTitleLimit($highlight->GetTitleLimit()); $new_highlight->SetAlternateKey(self::GetHighlightKey($highlight->GetName())); $new_highlight->SetConfigModule($highlight); $new_highlight->Enable(); /* * We don't use a refrence here as the source object will be replaced * after this iteration. */ $this->features[$new_highlight_key] = $new_highlight; // We now refrence the permanent object. $this->enabled_features[] =& $this->features[$new_highlight_key]; $this->registered_features[] = $new_highlight; } else { // If it does exist in the features $stored_highlight_key = self::GetHighlightKey($highlight->GetName()); $stored_highlight =& $this->features[$stored_highlight_key]; // Make sure its enabled $stored_highlight->Enable(); // Set the config module $stored_highlight->SetConfigModule($highlight); /* * This may change if we allow the users to set the content limit at a later date * for now, any changes to the limit in the config fail need to take immediate effect */ $stored_highlight->SetContentLimit($highlight->GetContentLimit()); $stored_highlight->SetTitleLimit($highlight->GetTitleLimit()); // Garbage collection and enabled state $this->registered_features[] =& $stored_highlight; $this->enabled_features[] = $stored_highlight_key; } // Set up ajax for it add_action('wp_ajax_opcp_' . self::GetHighlightKey($highlight->GetName()) . 'Activate', array($this->features[self::GetHighlightKey($highlight->GetName())], 'Activate')); add_action('wp_ajax_opcp_' . self::GetHighlightKey($highlight->GetName()) . 'Deactivate', array($this->features[self::GetHighlightKey($highlight->GetName())], 'Deactivate')); } } }
public function ResetImage() { $feature_key = $_POST['feature_key']; $image_key = $_POST['image_key']; $skin_name = $_POST['skin_name']; $feature = $this->features[$feature_key]; if (is_object($feature)) { $config_skins =& OnePanelConfig::GetSkins(); $config_images = $config_skins[$skin_name]->GetManagableImages(); $default = $config_images[$image_key]; $feature->UpdateImage($image_key, $default); OnePanel::PackData(); $response['new_image'] = $default; $response['preview_id'] = 'upload_preview_' . str_replace(' ', '_', $image_key); } else { die('Nothing by the name ' . $feature_key); } // TODO what if it fails? die(json_encode($response)); }