/**
  * 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);
 }
 /**
  * Sets up pages.
  * 
  * This method automatically gets triggered with the wp_loaded hook. 
  */
 public function setUp()
 {
     $_sCapability = FetchTweets_Option::get(array('capabilities', 'setting_page_capability'));
     if ($_sCapability) {
         $this->setCapability($_sCapability);
     }
     /* ( required ) Set the root page */
     $_sPostTypeSlug = FetchTweets_Commons::PostTypeSlug;
     $this->setRootMenuPageBySlug("edit.php?post_type={$_sPostTypeSlug}");
     /* ( required ) Add sub-menu items (pages or links) */
     $this->addSubMenuItems(array('title' => __('Contact', 'fetch-tweets'), 'page_slug' => 'fetch_tweets_contact', 'screen_icon' => 'feedback'));
     /* ( optional ) Disable the automatic settings link in the plugin listing table. */
     $this->setPluginSettingsLinkLabel('');
     // pass an empty string.
 }
 public function setUp()
 {
     $this->oOption = $GLOBALS['oFetchTweets_Option'];
     $_sCapability = FetchTweets_Option::get(array('capabilities', 'setting_page_capability'), 'manage_options');
     $this->setArguments(array('labels' => $this->oProp->bIsAdmin ? $this->_getPostTypeLabelArguments() : array(), 'public' => true, 'menu_position' => 110, 'supports' => array('title'), 'taxonomies' => array(''), 'menu_icon' => $this->oProp->bIsAdmin ? FetchTweets_Commons::getPluginURL('/asset/image/menu_icon_16x16.png') : '', 'has_archive' => true, 'hierarchical' => false, 'show_admin_column' => true, 'screen_icon' => $this->oProp->bIsAdmin ? FetchTweets_Commons::getPluginURL("/asset/image/screen_icon_32x32.png") : '', 'exclude_from_search' => !FetchTweets_Option::get(array('search', 'is_searchable')), 'capabilities' => array('publish_posts' => $_sCapability, 'edit_posts' => $_sCapability, 'edit_others_posts' => $_sCapability, 'delete_posts' => $_sCapability, 'delete_others_posts' => $_sCapability, 'read_private_posts' => $_sCapability, 'edit_post' => $_sCapability, 'delete_post' => $_sCapability, 'read_post' => $_sCapability)));
     $this->addTaxonomy(FetchTweets_Commons::TagSlug, array('labels' => $this->oProp->bIsAdmin ? $this->_getTaxonomyTagLabelArgumnents() : array(), 'show_ui' => true, 'show_tagcloud' => false, 'hierarchical' => false, 'show_admin_column' => true, 'show_in_nav_menus' => false, 'show_table_filter' => true, 'show_in_sidebar_menus' => true));
     $_sCurrentPostTypeInAdmin = isset($GLOBALS['post_type']) ? $GLOBALS['post_type'] : (isset($_GET['post_type']) ? $_GET['post_type'] : '');
     // For admin
     if ($_sCurrentPostTypeInAdmin == $this->oProp->sPostType && is_admin()) {
         $this->setAutoSave(false);
         $this->setAuthorTableFilter(true);
         add_filter('enter_title_here', array($this, '_replyToChangeTitleMetaBoxFieldLabel'));
         // add_filter( 'gettext', array( $this, 'changeTitleMetaBoxFieldLabel' ) );
         add_action('edit_form_after_title', array($this, 'addTextAfterTitle'));
     }
     // add_filter( 'the_content', array( $this, '_replyToPreviewTweets' ) );
 }
 /**
  * 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;
 }
 public function setUp()
 {
     $_sCapability = FetchTweets_Option::get(array('capabilities', 'setting_page_capability'));
     if ($_sCapability) {
         $this->setCapability($_sCapability);
     }
     $this->_setUpPages();
 }
 /**
  * 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']));
 }