/** * * @param array $options * @author Panagiotis Vagenas <*****@*****.**> * @since 2.0.0 */ protected function __construct($options) { if (!class_exists('erpQueryFormater')) { erpPaths::requireOnce(erpPaths::$erpQueryFormater); } if (!class_exists('erpRatingSystem')) { erpPaths::requireOnce(erpPaths::$erpRatingSystem); } if (!class_exists('erpRelData')) { erpPaths::requireOnce(erpPaths::$erpRelData); } $this->options = $options; }
" data-tooltip title="Set the colour if the post excerpt. Default color is white. If white is selected your themes default color for paragraphs, will be used as related posts title color"/> </td> </tr> </table> <hr> <table class="erp-wid-table"> <tr> <td colspan="2" style="text-align: center"> <strong>Themes</strong> </td> </tr> <tr> <?php erpPaths::requireOnce(erpPaths::$VPluginThemeFactory); VPluginThemeFactory::registerThemeInPathRecursive(erpPaths::getAbsPath(erpPaths::$widgetThemesFolder)); $templates = VPluginThemeFactory::getThemesNames(); ?> <td><label for="<?php echo $widgetInstance->get_field_id('dsplLayout'); ?> ">Theme :</label></td> <td> <select class="dsplLayout" data-widinst="<?php echo $widgetInstance->get_field_id('dsplLayout'); ?> " name="<?php echo $widgetInstance->get_field_name('dsplLayout');
private static function delWidOptions() { erpPaths::requireOnce(erpPaths::$erpWidOpts); $wOpts = new erpWidOpts(); delete_option($wOpts->getOptionsArrayName()); }
/** * Get default thumb url * @return string|NULL * @author Panagiotis Vagenas <*****@*****.**> * @since 2.0.0 */ public function getDefaultThumbnail() { if ($this instanceof erpMainOpts) { $t = $this->getValue('defaultThumbnail'); } else { erpPaths::requireOnce(erpPaths::$erpMainOpts); $mOpts = new erpMainOpts(); $t = $mOpts->getDefaultThumbnail(); } return !empty($t) ? $t : erpDefaults::$comOpts['defaultThumbnail']; }
/** * Uses bfi resizer to resize image and returns url to new image * @param string $url * @param int $width * @param int $height * @param bool $crop * @return string * @author Panagiotis Vagenas <*****@*****.**> * @since 2.0.0 */ private function resize($url, $width = NULL, $height = NULL, $crop = true) { erpPaths::requireOnce(erpPaths::$bfiResizer); return bfi_thumb($url, array('width' => $width, 'height' => $height, 'crop' => $crop)); }
} /* ----------------------------------------------------------------------------* * Public-Facing Functionality * ---------------------------------------------------------------------------- */ erpPaths::requireOnce(erpPaths::$erpWidget); erpPaths::requireOnce(erpPaths::$easyRelatedPosts); /* * Register hooks that are fired when the plugin is activated or deactivated. * When the plugin is deleted, the uninstall.php file is loaded. */ register_activation_hook(__FILE__, array('easyRelatedPosts', 'activate')); register_deactivation_hook(__FILE__, array('easyRelatedPosts', 'deactivate')); /** * Register plugin and widget */ add_action('plugins_loaded', array('easyRelatedPosts', 'get_instance')); function regERPWidget() { register_widget("ERP_Widget"); } add_action('widgets_init', 'regERPWidget'); /* ----------------------------------------------------------------------------* * Dashboard and Administrative Functionality * ---------------------------------------------------------------------------- */ /** */ if (is_admin()) { erpPaths::requireOnce(erpPaths::$easyRelatedPostsAdmin); erpPaths::requireOnce(erpPaths::$WP_Admin_Notices); add_action('plugins_loaded', array('easyRelatedPostsAdmin', 'get_instance')); }
/** * This is called through ajax hook and returns the plugin options as defined in template settings file * * @author Panagiotis Vagenas <*****@*****.**> * @since 2.0.0 */ public function loadTemplateOptions() { if (!isset($_POST['template']) || !isset($_POST['templateRoot'])) { echo json_encode(false); die; } erpPaths::requireOnce(erpPaths::$VPluginThemeFactory); VPluginThemeFactory::registerThemeInPathRecursive(erpPaths::getAbsPath(erpPaths::$mainThemesFolder), $_POST['template']); $theme = VPluginThemeFactory::getThemeByName($_POST['template']); $data = array(); if ($theme) { $data = array('content' => $theme->renderSettings('', false), 'optionValues' => $theme->getOptions()); } echo json_encode($data); die; }
/** * Sanitize widget form values as they are saved. * * @see WP_Widget::update() * * @param array $new_instance * Values just sent to be saved. * @param array $old_instance * Previously saved values from database. * @return array Updated safe values to be saved. * @since 2.0.0 * @author Panagiotis Vagenas <*****@*****.**> */ public function update($new_instance, $old_instance) { /* #? Verify nonce */ if (!isset($_POST['erp_meta_box_nonce']) || !wp_verify_nonce($_POST['erp_meta_box_nonce'], 'erp_meta_box_nonce')) { return; } erpPaths::requireOnce(erpPaths::$erpWidOpts); // get an instance to validate options $widOpts = new erpWidOpts($old_instance); // validate wid options $widOptsValidated = $widOpts->saveOptions($new_instance, $old_instance); // validate template options if (isset($new_instance['dsplLayout'])) { erpPaths::requireOnce(erpPaths::$VPluginThemeFactory); VPluginThemeFactory::registerThemeInPathRecursive(erpPaths::getAbsPath(erpPaths::$widgetThemesFolder), $new_instance['dsplLayout']); $theme = VPluginThemeFactory::getThemeByName($new_instance['dsplLayout']); if ($theme) { $themeValidated = $theme->saveSettings($new_instance); foreach ($theme->getDefOptions() as $key => $value) { unset($new_instance[$key]); } } else { $message = new WP_Error_Notice('Theme ' . $new_instance['dsplLayout'] . ' not found. Theme options discarded'); WP_Admin_Notices::getInstance()->addNotice($message); } } // save updated options return $widOptsValidated + $themeValidated; }
<?php /** * Easy related posts . * * @package Easy_Related_Posts_Options * @author Panagiotis Vagenas <*****@*****.**> * @link http://erp.xdark.eu * @copyright 2014 Panagiotis Vagenas <*****@*****.**> */ erpPaths::requireOnce(erpPaths::$erpOptions); /** * Widget options class. * * @package Easy_Related_Posts_Options * @author Panagiotis Vagenas <*****@*****.**> */ class erpWidOpts extends erpOptions { public function __construct(array $instance = NULL) { parent::__construct(); $this->optionsArrayName = 'widget_' . erpDefaults::erpWidgetOptionsArrayName; $this->defaults = erpDefaults::$widOpts + erpDefaults::$comOpts; if ($instance !== NULL && !empty($instance)) { $this->options = $instance; } else { $this->options = $this->defaults; } } /**
* it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ /** * @copyright 2014 Panagiotis Vagenas <*****@*****.**> */ erpPaths::requireOnce(erpPaths::$erpTheme); /** * Description of erpTheme * * @author Panagiotis Vagenas <*****@*****.**> */ class erpBasicListWidTheme extends erpTheme { /** * The name of the theme * @var string */ protected $name = 'Basic list'; /** * A description for theme * @var string
/** * Fired for each blog when the plugin is activated. * * @since 2.0.0 */ private static function single_activate() { erpPaths::requireOnce(erpPaths::$erpActivator); $compareVersions = erpDefaults::compareVersion(get_option(erpDefaults::versionNumOptName)); if ($compareVersions < 0) { // New install /** * If an old version is present translate options */ if (get_option('erpVersion')) { $mainOpts = self::migrateMainOptions(); $notice = new WP_Updated_Notice('<strong>Easy Related Posts updated from V1 to V2.</strong>' . 'You should review the main plugin and widget settings.<br>' . 'There are some major changes in this version and this affects options as well. ' . 'We are sorry for the inconvenience but this was necessary to move this plugin forward'); WP_Admin_Notices::getInstance()->addNotice($notice); // Delete old options delete_option('erpVersion'); delete_option('erpSubVersion'); delete_option('erpOpts'); } else { $mainOpts = erpDefaults::$comOpts + erpDefaults::$mainOpts; } erpActivator::addNonExistingMainOptions($mainOpts, EPR_MAIN_OPTIONS_ARRAY_NAME); erpActivator::addNonExistingWidgetOptions(erpDefaults::$comOpts + erpDefaults::$mainOpts, 'widget_' . erpDefaults::erpWidgetOptionsArrayName); erpDefaults::updateVersionNumbers(); } elseif ($compareVersions === 0) { // Major update erpDefaults::updateVersionNumbers(); } elseif ($compareVersions === 1) { // Release update erpDefaults::updateVersionNumbers(); } elseif ($compareVersions === 2) { // Minor update erpDefaults::updateVersionNumbers(); } }
public function formPostData(WP_Query $wpq, erpOptions $optionsObj, $ratings = array()) { erpPaths::requireOnce(erpPaths::$erpPostData); $data = array('title' => $optionsObj->getValue('title'), 'options' => $this->options, 'uniqueID' => $this->uniqueID, 'optionsObj' => $optionsObj, 'posts' => array()); while ($wpq->have_posts()) { $wpq->the_post(); $rating = isset($ratings[get_the_ID()]) ? $ratings[get_the_ID()] : null; $postData = new erpPostData($wpq->post, $optionsObj, $rating); if ($optionsObj->haveToShowExcerpt()) { $postData->setExcerpt($optionsObj->getValue('excLength'), $optionsObj->getValue('moreTxt')); } if ($optionsObj->haveToShowThumbnail()) { $postData->setThumbnail($optionsObj->getDefaultThumbnail()); } array_push($data['posts'], $postData); } wp_reset_postdata(); $this->setAdditionalViewData(array_merge($data, $this->options)); return $this; }