Ad Manager Having problems getting ads to show

Discussion in 'General Support and Questions' started by gldtn, Jan 6, 2012.

  1. gldtn New Member

    Hello,

    I have tried every possible way to try to get ads, to show, but no matter what criteria I choose, I don't see anything.

    1. I made sure the Ad is active,
    2. Tried choosing 1(one) position,
    3. Tried choosing ALL the positions,
    4. Tried adding criteria(is moderator, is administrator),
    5. Tried adding criteria(is logged in),
    6. Tried adding criteria(user state is valid),
    7. Checked in the default Xenforo permission system and did not see anything relate to Ad Manager,
    8. Tried all the above w/both image banner & custom code.
    The only thing I can think of why it's not working, it seems to me the Donation add-on and this add-on uses some of the same files?, unless the Ad manager folder structer was wrong on the zip file.

    /library/Merc
    /library/XenPlus

    Any ideas?
  2. Robbo Staff Member

    All my add-ons use XenPlus and are located inside Merc. I can't think of anything right now so let's start with some tests.
    First create a new custom code ad and just add contents "test" and then go to positions and just set to header.
    Now check for it and we will assume it isn't working. Check your error log for problems.

    That's all for now. If you don't have any errors then a listener might not be functioning or something, a few details just incase they might apply later..

    XenForo Version:
    PHP Version:
    Go into /library/XenPlus/Installer.php and paste the contents.
  3. gldtn New Member

    Nothing in the error logs;

    XenForo Version: 1.1.0
    PHP Version: 5.2.17
  4. Robbo Staff Member

    And the XenPlus file?
  5. gldtn New Member

    PHP:
    <?php
     
    abstract class XenPlus_Installer
    {
        protected 
    $_db;
     
        protected 
    $_existingAddon;
     
        protected 
    $_addonData;
     
        protected 
    $_rebuildContentCache false;
     
        protected static 
    $_modelCache = array();
     
        public function 
    __construct($existingAddon$addonData null)
        {
            
    $this->_db XenForo_Application::get('db');
            
    $this->_existingAddon $existingAddon;
            
    $this->_addonData $addonData;
        }
     
        public function 
    __destruct()
        {
            if (
    $this->_rebuildContentCache)
            {
                
    XenForo_Model::create('XenForo_Model_ContentType')->rebuildContentTypeCache();
            }
        }
     
        public static function 
    install($existingAddon$addonData)
        {
            
    $class self::_getClass();
            
    $installer = new $class($existingAddon$addonData);
            return 
    $installer->runInstall();
        }
     
        public static function 
    uninstall($existingAddon)
        {
            
    $class self::_getClass();
            
    $installer = new $class($existingAddon);
            return 
    $installer->runUninstall();
        }
     
        protected static function 
    _getClass()
        {
            if (
    version_compare(phpversion(), '5.3') != -1)
                return 
    get_called_class();
     
            
    $backtrace debug_backtrace();
            
    $args false;
            foreach(
    $backtrace as $key => $trace)
            {
                if (
    $trace['function'] == 'call_user_func')
                {
                    
    $args $trace['args'];
                    break;
                }
            }
     
            if (!
    $args || empty($args[0][0]))
                throw new 
    XenForo_Exception('Failed to make XenPlus compatible with PHP 5.2');
     
            return 
    $args[0][0];
        }
     
        public function 
    runInstall()
        {
            
    $start 1;
     
            if (
    $this->_existingAddon)
                
    $start += $this->_existingAddon['version_id'];
     
            
    $this->_preInstall();
     
            
    XenForo_Db::beginTransaction($this->_db);
     
            try
            {
                for (
    $v $start$v <= $this->_addonData['version_id']; ++$v)
                      
    $this->_callVersionMethod($v);
            }
            catch (
    Exception $e)
            {
                
    XenForo_Db::rollback($this->_db);
                throw 
    $e;
            }
     
            
    XenForo_Db::commit($this->_db);
     
            
    $this->_postInstall();
     
            return 
    true;
        }
     
        public function 
    runUninstall()
        {
            
    XenForo_Db::beginTransaction($this->_db);
     
            try
            {
                for (
    $v $this->_existingAddon['version_id']; $v >= 0; --$v)
                    
    $this->_callVersionMethod($vtrue);
            }
            catch (
    Exception $e)
            {
                
    XenForo_Db::rollback($this->_db);
                throw 
    $e;
            }
     
            
    XenForo_Db::commit($this->_db);
     
            return 
    true;
        }
     
        protected function 
    _preInstall()
        {
     
        }
     
        protected function 
    _postInstall()
        {
     
        }
     
        protected function 
    _callVersionMethod($version$uninstall false)
        {
            if (
    method_exists($this'_' . ($uninstall 'un' '') . 'installVersion' $version))
                
    $this->{'_' . ($uninstall 'un' '') . 'installVersion' $version}();
        }
     
        protected function 
    _bulkAddContentType(array $types)
        {
            if (!
    is_array($types))
                return;
     
            foreach (
    $types as $type => $pairs)
            {
                if (!
    is_array($pairs))
                    continue;
     
                foreach (
    $pairs as $name => $value)
                    
    $this->_addContentType($type$name$value);
            }
        }
     
        protected function 
    _addContentType($type$name$value)
        {
            
    $this->_rebuildContentCache true;
     
            if (!
    $this->_db->fetchRow('SELECT * FROM xf_content_type_field WHERE content_type = ? AND field_name = ?', array($type$name)))
                
    $this->_db->insert('xf_content_type_field', array(
                    
    'content_type' => $type,
                    
    'field_name' => $name,
                    
    'field_value' => $value)
                );
     
            if (!
    $this->_db->fetchRow('SELECT * FROM xf_content_type WHERE content_type = ?'$type))
                
    $this->_db->insert('xf_content_type', array('content_type' => $type'addon_id' => $this->_addonData['addon_id'], 'fields' => ''));
        }
     
        protected function 
    _removeContentType($type$name null)
        {
            
    $this->_rebuildContentCache true;
     
            
    $handlers = array(
                
    'alert_handler_class' => 'xf_user_alert',
                
    'news_feed_handler_class' => 'xf_news_feed',
                
    'report_handler_class' => array('xf_report''_removeReportComments'),
                
    // TODO: add the rest of the possible handlers
            
    );
     
            
    $single false;
            if (
    $name && isset($handlers[$name]))
                
    $single $handlers[$name];
            
    //else
                //$name = '*';
     
            
    $this->_db->delete('xf_content_type', array('content_type = ?' => $type));
            
    $this->_db->delete('xf_content_type_field', array('content_type = ? AND field_name = ?' => array($type$name)));
     
            if (
    $single)
            {
                if (
    is_array($single))
                {
                    if (
    method_exists($this$single[1]))
                        
    $this->$single[1]($type);
     
                    
    $single $single[0];
                }
     
                
    $this->_db->delete($single, array('content_type = ?' => $type));
                return;
            }
     
            foreach (
    $handlers as $handle)
            {
                if (
    is_array($handle))
                {
                    if (
    method_exists($this$handle[1]))
                        
    $this->$handle[1]($type);
     
                    
    $handle $handle[0];
                }
     
                
    $this->_db->delete($handle, array('content_type = ?' => $type));
            }
        }
     
        protected function 
    _removeReportComments($type)
        {
            
    $reportIds $this->_db->fetchCol('SELECT report_id FROM xf_report WHERE content_type = ?'$type);
            if (!empty(
    $reportIds))
                
    $this->_db->delete('xf_report_comment', array('report_id IN (' implode(','$reportIds) . ')'));
        }
     
        protected function 
    _addTableColumn($table$field$info$after ''$overwriteIfExists false)
        {
            
    $columns $this->_db->describeTable($table);
     
            
    $action 'ADD';
            if (isset(
    $columns[$field]))
            {
                if (!
    $overwriteIfExists)
                    return;
     
                
    $action "CHANGE `$field`";
            }
     
            if (isset(
    $columns[$after]) && !isset($columns[$field]))
                
    $info .= ' AFTER ' $after;
     
            
    $this->_db->query("ALTER TABLE `$table$action `$field$info");
        }
     
        protected function 
    _addValueToColumnEnum($table$column$values)
        {
            
    $field $this->_db->fetchRow('
                SELECT *
                FROM information_schema.columns
                WHERE table_name = ? AND column_name = ?'
            
    , array($table$column));
     
            if (!
    $field || strpos($field['COLUMN_TYPE'], 'enum(') !== 0)
                return;
     
            if (!
    is_array($values))
                
    $values = array($values);
     
            
    $originalValues explode("','"substr($field['COLUMN_TYPE'], 6strlen($field['COLUMN_TYPE']) - 8));
            foreach (
    $values as $k => $value)
                if (
    in_array($value$originalValues))
                    unset(
    $values[$k]);
     
            if (empty(
    $values))
                return;
     
            
    $enum "enum('" implode("','"array_merge($originalValues$values)) . "')";
            
    $info $enum ' CHARACTER SET ' $field['CHARACTER_SET_NAME'] . ' COLLATE ' $field['COLLATION_NAME'] . ' DEFAULT \'' $field['COLUMN_DEFAULT'] . '\' ' . ($field['IS_NULLABLE'] == 'YES' 'NULL' 'NOT NULL');
            
    $this->_addTableColumn($table$column$info''true);
        }
     
        protected function 
    _removeValueFromColumnEnum($table$column$values)
        {
            
    $field $this->_db->fetchRow('
                SELECT *
                FROM information_schema.columns
                WHERE table_name = ? AND column_name = ?'
            
    , array($table$column));
     
            if (!
    $field || strpos($field['COLUMN_TYPE'], 'enum(') !== 0)
                return;
     
            if (!
    is_array($values))
                
    $values = array($values);
     
            
    $enum explode("','"substr($field['COLUMN_TYPE'], 6strlen($field['COLUMN_TYPE']) - 8));
            foreach (
    $enum as $k => $e)
                if (
    in_array($e$values))
                    unset(
    $enum[$k]);
     
            
    $enum "enum('" implode("','"$enum) . "')";
            
    $info $enum ' CHARACTER SET ' $field['CHARACTER_SET_NAME'] . ' COLLATE ' $field['COLLATION_NAME'] . ' DEFAULT \'' $field['COLUMN_DEFAULT'] . '\' ' . ($field['IS_NULLABLE'] == 'YES' 'NULL' 'NOT NULL');
            
    $this->_addTableColumn($table$column$info''true);
        }
     
        protected function 
    _removeTableColumn($table$field)
        {
            
    $columns $this->_db->describeTable($table);
     
            if (isset(
    $columns[$field]))
            {
                
    $this->_db->query("ALTER TABLE $table DROP COLUMN $field");
            }
        }
     
        protected function 
    _getModelFromCache($class)
        {
            if (!isset(
    self::$_modelCache[$class]))
            {
                
    self::$_modelCache[$class] = XenForo_Model::create($class);
            }
     
            return 
    self::$_modelCache[$class];
        }
     
     
    }
  6. Robbo Staff Member

    Ok nothing there. Go into acp -> development tools (needs to be in debug mode) -> code event listeners and tell me if template hook is there under ad manager.
  7. Robbo Staff Member

    Another thing. What other mods have you got installed?
  8. gldtn New Member

    Yes, it's there.

    Donation Manager,
    Nodes As Tabs,
    Post Ratings,
    Taigachat,
    The Happy Place,
    XenCarta Wiki
    BD Reputation System,
    BD Tag me,
    xfr User Albums

    Edit:
    I tried disabling all of them and left only the Ad Manager on, but no luck!
  9. Robbo Staff Member

    Ok I would say one of these is preventing a listener from firing or overwriting some changes. I will go through what I use and then what other mods use. Pretty busy right now so if I don't reply more say within an hour bump me by posting here again.
    gldtn likes this.
  10. Robbo Staff Member

    Just had a look at how I am displaying ads and there is no reason a mod should stop this unless coded poorly. I really can't think of a thing. Are you on a test site that you can add code where I say and tell me what happens? Can you try a fresh install somewhere to see if it works? Also a custom style could get in the way if it messes with template hooks.
  11. gldtn New Member

    I'm currently at work, so I can't access my dev installation at this time. I designed the theme myself, so I know there is no hooks on it, I've also tried using the default Xenforo skin.

    The only hook I manually placed was for the Post Ratings mod, on ad_message_below;
    Code:
    <xen:hook name="message_below" params="{xen:array 'post={$message}','message_id={$messageId}'}" />
    I tried uninstalling the Ad Manager, but it seems like it's leaving a table behide:
    Code:
    Server Error
     
    Mysqli statement execute error : Table 'merc_ad' already exists
    When I get home I'll delete it and try again, and will also try on my dev installation.

    Not at the moment, but can you reply with what you want me to try, that way when I get home tonight I can try and let you know if I get anything.

    Thanks!
  12. Robbo Staff Member

    Well hooks are where positions works. Since you designed the theme this actually leaves you in a powerful position for where you want to add your ads. Go into debug mode and you will see ad manager positions under ACP -> Ad Manager. Basically they use any hook in a template to append or prepend to. So wherever you want your ads simple ad a hook <xen:hook name="my_ad_hook_here" /> and then create a new position that uses that hook. This is a powerful aspect of the ad manager that is undocumented at the moment. Give it a go and see if you can figure it out :)
  13. gldtn New Member

    Ok,

    I tried adding a new position but I'm getting a mysql error:
    Code:
    Server Error
     
    Mysqli prepare error: Unknown column 'position' in 'field list'
     
    Zend_Db_Statement_Mysqli->_prepare() in Zend/Db/Statement.php at line 115
    Zend_Db_Statement->__construct() in Zend/Db/Adapter/Mysqli.php at line 381
    Zend_Db_Adapter_Mysqli->prepare() in Zend/Db/Adapter/Abstract.php at line 478
    Zend_Db_Adapter_Abstract->query() in Zend/Db/Adapter/Abstract.php at line 574
    Zend_Db_Adapter_Abstract->insert() in XenForo/DataWriter.php at line 1591
    XenForo_DataWriter->_insert() in XenForo/DataWriter.php at line 1580
    XenForo_DataWriter->_save() in XenForo/DataWriter.php at line 1381
    XenForo_DataWriter->save() in Merc/ControllerAdmin/Ads/Position.php at line 92
    Merc_ControllerAdmin_Ads_Position->actionPositionSave() in XenForo/FrontController.php at line 310
    XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 132
    XenForo_FrontController->run() in /home/cogumelo/public_html/comunidade/admin.php at line 13
    The good news is, that I got it to work on my dev site at home. So maybe something to do with my other add-ons maybe, I tried disabling one by one, but did not have any luck; Would you like my login info and take a look yourself? I'll shoot you a PM

    BTW: My dev installation has the same theme, so I think it's save to rule out the forum skin.
  14. Vincent Staff Member

    That error comes up here too, so it's not just you.
    I'm sure Robbo will look into it tomorrow, he's probably asleep or hunting kangaroos.
  15. Robbo Staff Member

    Oh yeah I completely forgot about that error. I will have to get a minor release out over the weekend to get you going. For now you can either try editing one of the other positions to use your hook or just name your hook the same as one of the other ones uses.
  16. gldtn New Member

    I guess I'll have to wait till you get a fix out, because I can not rename any positions.. I get the same error above! Also renaming my hook to the existing one turns out nothing :/, wonder why it works on my dev site and not on my live site :confused:
  17. Robbo Staff Member

    Does your dev site use your custom theme? I'll get a release out for this tonight.
  18. gldtn New Member

    Yes it does, and it works on all my custom themes. The only other thing I can think of is something to do with an option on my server maybe? When I get home tonight I'll try to set up another dev site on the server to try to rule that out.

    No worries, and thanks!
  19. Robbo Staff Member

    Ok follow these steps for a fix to this issue and see if you can get yourself sorted.

    Open file library/Merc/DataWriter/Ads/Position.php and replace line 17...
    Code:
    'position' => array('type' => self::TYPE_STRING, 'allowedValues' => array('after', 'before'), 'default' => 'after'), 
    with this...
    Code:
    'placement' => array('type' => self::TYPE_STRING, 'allowedValues' => array('after', 'before'), 'default' => 'after'),
  20. gldtn New Member

    Robbo, after editing the datawriter, I get the following error:

    EDITED:

    I betting it's an add-on causing the problem Robbo, I just setup a dev site on the same server and the ads are showing up fine. When I have time I'll install all the add-ons I have on my live site to the dev site one by one and see if I can find the cause of this. Although I thought if I disabled the add-ons it should've ruled it out.

Share This Page