/** * Sets up properties. * @since 2.3.9 * @param string|array The template slug. If it is an empty, the default template will be set. * Or if it is array, it is considers as the template definition array. Use it for inactive templates. */ public function __construct($asTemplateSlugOrData = '') { $this->oOption = FetchTweets_Option::getInstance(); if (is_array($asTemplateSlugOrData)) { $this->aData = $asTemplateSlugOrData; return; } // At this point a string slug is given. $_sTemplateSlug = $asTemplateSlugOrData; if (!$_sTemplateSlug) { $this->aData = $this->_getDefault(); return; } $this->aData = $this->_getTemplateBySlug($_sTemplateSlug); }
/** * Returns an array holding the labels(names) of activated templates. * * This is used for the widget form or the template meta box to let the user select a template. * * @since unknown * @since 2.3.9 Moved form the templates class. */ public static function getTemplateArrayForSelectLabel($aTemplates = null) { $_oOption = FetchTweets_Option::getInstance(); if (!$aTemplates) { $aTemplates = $_oOption->getActiveTemplates(); } $_aLabels = array(); foreach ($aTemplates as $_sSlug => $_aTemplate) { $_oTemplate = new FetchTweets_Template($_aTemplate['sSlug']); $_sName = $_oTemplate->get('sName'); if (!$_sName) { continue; } // it may be broken. $_aLabels[$_aTemplate['sSlug']] = $_sName; } return $_aLabels; }
/** * Loads the file of active template of the given file name. * * @since 2.3.9 * @param string $sFileName The file base name with file extension to load. * @param string $sMethod The method to load. Either 'include' or 'enqueue_style' is accepted. Use 'enqueue_style' for styles. */ private function _loadFileOfActiveTemplatesByFileName($sFileName = 'functions.php', $sMethod = 'include') { $_oOption = FetchTweets_Option::getInstance(); foreach ($_oOption->getActiveTemplates() as $_aTemplate) { $_oTemplate = new FetchTweets_Template($_aTemplate['sSlug']); $_sFilePath = $_oTemplate->getPathByFileName($sFileName); if (!$_sFilePath) { continue; } if (in_array($_sFilePath, self::$_aLoaded)) { continue; } self::$_aLoaded[$_sFilePath] = $_sFilePath; switch ($sMethod) { default: case 'include': include $_sFilePath; break; case 'enqueue_style': wp_register_style("fetch-tweets-" . md5($_aTemplate['sDirPath']), FetchTweets_WPUtilities::getSRCFromPath($_sFilePath)); wp_enqueue_style("fetch-tweets-" . md5($_aTemplate['sDirPath'])); break; } } }
/** * Loads all necessary plugin components. * * @remark A callback of the 'plugins_loaded' action hook. */ public function _replyToLoadPluginComponents() { do_action('fetch_tweets_action_before_loading_plugin'); // 2. Option Object - the instantiation will handle the initial set-up FetchTweets_Option::getInstance(); // 3. Load active templates - this must be done after loading the option class as it stores active templates. new FetchTweets_TemplatesLoader(); // 4. Admin pages if ($this->_bIsAdmin) { new FetchTweets_AdminPage(FetchTweets_Commons::$sAdminKey, $this->_sFilePath); new FetchTweets_AdminPage_Contact('', $this->_sFilePath); } // 5. Post Type - no need to check is_admin() because posts of custom post type can be accessed from the front-end. new FetchTweets_PostType(FetchTweets_Commons::PostTypeSlug, null, $this->_sFilePath); // post type slug // 6. Meta-boxes if ($this->_bIsAdmin) { $this->_registerMetaBoxes(); } // 7. Shortcode - enables the shortcode. e.g. [fetch_tweets id="143"] new FetchTweets_Shortcode('fetch_tweets'); // 8. Widgets add_action('widgets_init', 'FetchTweets_WidgetByID::registerWidget'); add_action('widgets_init', 'FetchTweets_WidgetByTag::registerWidget'); // 9. Events - handles background processes. new FetchTweets_Event(); // 10. MISC if (FetchTweets_PluginUtility::isInPluginAdminPage()) { $GLOBALS['oFetchTweetsUserAds'] = isset($GLOBALS['oFetchTweetsUserAds']) ? $GLOBALS['oFetchTweetsUserAds'] : new FetchTweets_UserAds(); } // 11. WordPress version backward compatibility. $this->_defineConstantesForBackwardCompatibility(); do_action('fetch_tweets_action_after_loading_plugin'); }
/** * Deals with the bulk actions. * * Called from outside. * @todo Adapt the new template format. */ public function process_bulk_action() { if (!isset($_REQUEST['template'])) { return; } $_oOption = FetchTweets_Option::getInstance(); switch (strtolower($this->current_action())) { case 'activate': foreach ((array) $_REQUEST['template'] as $_sTemplateSlug) { $_oTemplate = $this->aData[$_sTemplateSlug]; $_oTemplate->aData['bIsActive'] = true; $_oOption->aOptions['arrTemplates'][$_sTemplateSlug] = $_oTemplate->aData; } break; case 'deactivate': foreach ((array) $_REQUEST['template'] as $_sTemplateSlug) { // $this->aData[ $_sTemplateSlug ]['bIsActive'] = false; // the option array only stores active templates. unset($_oOption->aOptions['arrTemplates'][$_sTemplateSlug]); } break; case 'set_default': if (!is_string($_REQUEST['template'])) { return; } // Set the other templates not to be default. foreach ($_oOption->aOptions['arrTemplates'] as &$_aTemplate) { // the saved template option array $_aTemplate['bIsDefault'] = false; } unset($_oTemplate); // release the reference in foreach(), to be safe. // Enable the selected default template. $_aDefaultTemplate = $this->aData[$_REQUEST['template']]->aData; $_aDefaultTemplate['bIsDefault'] = true; $_oOption->aOptions['arrTemplates'][$_REQUEST['template']] = $_aDefaultTemplate; $_oOption->aOptions['arrDefaultTemplate'] = $_aDefaultTemplate; break; default: return; // do nothing. } $_oOption->saveOptions(); wp_redirect(admin_url('edit.php?post_type=' . FetchTweets_Commons::PostTypeSlug . '&page=' . FetchTweets_Commons::$aPageSlugs['template'])); }