Esempio n. 1
0
 function insert(&$object, $force = true)
 {
     if ($ret = parent::insert($object, $force)) {
         $object->unsetNew();
     }
     return $ret;
 }
Esempio n. 2
0
 function insert(&$category)
 {
     parent::insert($category, true);
     if ($category->isNew()) {
         $this->applyPermissionTemplate($category);
     }
     return $category->getVar('cat_id');
 }
Esempio n. 3
0
 function insert(&$forum)
 {
     if (!parent::insert($forum, true)) {
         return false;
     }
     if ($forum->isNew()) {
         $this->applyPermissionTemplate($forum);
     }
     return $forum->getVar('forum_id');
 }
Esempio n. 4
0
 /**
  * @param object $obj
  *
  * @return mixed
  */
 function insert($obj)
 {
     $obj->setVar('last_modified', time());
     return parent::insert($obj);
 }
Esempio n. 5
0
 function insert($obj, $force = true)
 {
     error_reporting(E_ALL);
     xoops_load('cache');
     $read = XoopsCache::read('spider_id%%' . $obj->getVar('id'));
     if (!is_array($read)) {
         $value = '0A';
     } else {
         $value = $read['value'];
     }
     $value++;
     $read = XoopsCache::delete('spider_id%%' . $obj->getVar('id'));
     $read = XoopsCache::write('spider_id%%' . $obj->getVar('id'), array('value' => $value));
     $modulehandler =& xoops_gethandler('module');
     $confighandler =& xoops_gethandler('config');
     $xoModule = $modulehandler->getByDirname('spiders');
     $xoConfig = $confighandler->getConfigList($xoModule->getVar('mid'), false);
     if ($xoConfig['xortify_shareme'] == true) {
         // Connect to API
         $api = $this->apimethod();
         include_once $GLOBALS['xoops']->path('/modules/spiders/class/' . $api . '.php');
         $func = strtoupper($api) . 'SpidersExchange';
         $exchange = new $func();
         //Form Associated Array
         $spiders_handler =& xoops_getmodulehandler('spiders', 'spiders');
         $spider = $spiders_handler->get($obj->getVar('id'));
         $ret = array();
         $ret['useragent'] = $obj->getVar('useragent');
         $ret['netaddy'] = $obj->getVar('netaddy');
         $ret['ip'] = $obj->getVar('ip');
         $ret['server-ip'] = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR'];
         $obj->setVar('server-ip', isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR']);
         $ret['when'] = $obj->getVar('when');
         $ret['uri'] = $obj->getVar('uri');
         $ret['sitename'] = $GLOBALS['xoopsConfig']['sitename'];
         $ret['robot-name'] = $spider->getVar('robot-name');
         $ret['robot-id'] = $spider->getVar('robot-id');
         //Send to API
         $exchange->sendStatistic($ret);
     }
     // Clear Statistics - Save on database size
     $modulehandler = xoops_gethandler('module');
     $confighandler = xoops_gethandler('config');
     $xoMod = $modulehandler->getByDirname('spiders');
     $xoConfig = $confighandler->getConfigList($xoMod->getVar('mid'));
     $criteria = new Criteria('when', time() - $xoConfig['weeks_stats'] * (60 * 60 * 24 * 7), '<');
     $this->deleteAll($criteria, true);
     return parent::insert($obj, $force);
 }
Esempio n. 6
0
 /**
  * save a profile field in the database
  *
  * @param object $obj reference to the object
  * @param bool $force whether to force the query execution despite security settings
  * @param bool $checkObject check if the object is dirty and clean the attributes
  * @return bool FALSE if failed, TRUE if already present and unchanged or successful
  */
 function insert(&$obj, $force = false)
 {
     $profile_handler =& xoops_getmodulehandler('profile', 'profile');
     $obj->setVar('field_name', str_replace(' ', '_', $obj->getVar('field_name')));
     $obj->cleanVars();
     $defaultstring = "";
     switch ($obj->getVar('field_type')) {
         case "datetime":
         case "date":
             $obj->setVar('field_valuetype', XOBJ_DTYPE_INT);
             $obj->setVar('field_maxlength', 10);
             break;
         case "longdate":
             $obj->setVar('field_valuetype', XOBJ_DTYPE_MTIME);
             break;
         case "yesno":
             $obj->setVar('field_valuetype', XOBJ_DTYPE_INT);
             $obj->setVar('field_maxlength', 1);
             break;
         case "textbox":
             if ($obj->getVar('field_valuetype') != XOBJ_DTYPE_INT) {
                 $obj->setVar('field_valuetype', XOBJ_DTYPE_TXTBOX);
             }
             break;
         case "autotext":
             if ($obj->getVar('field_valuetype') != XOBJ_DTYPE_INT) {
                 $obj->setVar('field_valuetype', XOBJ_DTYPE_TXTAREA);
             }
             break;
         case "group_multi":
         case "select_multi":
         case "checkbox":
             $obj->setVar('field_valuetype', XOBJ_DTYPE_ARRAY);
             break;
         case "language":
         case "timezone":
         case "theme":
             $obj->setVar('field_valuetype', XOBJ_DTYPE_TXTBOX);
             break;
         case "dhtml":
         case "textarea":
             $obj->setVar('field_valuetype', XOBJ_DTYPE_TXTAREA);
             break;
     }
     if ($obj->getVar('field_valuetype') == "") {
         $obj->setVar('field_valuetype', XOBJ_DTYPE_TXTBOX);
     }
     if (!in_array($obj->getVar('field_name'), $this->getUserVars())) {
         if ($obj->isNew()) {
             //add column to table
             $changetype = "ADD";
         } else {
             //update column information
             $changetype = "CHANGE `" . $obj->getVar('field_name', 'n') . "`";
         }
         $maxlengthstring = $obj->getVar('field_maxlength') > 0 ? "(" . $obj->getVar('field_maxlength') . ")" : "";
         //set type
         switch ($obj->getVar('field_valuetype')) {
             default:
             case XOBJ_DTYPE_ARRAY:
             case XOBJ_DTYPE_UNICODE_ARRAY:
                 $type = "mediumtext";
                 break;
             case XOBJ_DTYPE_UNICODE_EMAIL:
             case XOBJ_DTYPE_UNICODE_TXTBOX:
             case XOBJ_DTYPE_UNICODE_URL:
             case XOBJ_DTYPE_EMAIL:
             case XOBJ_DTYPE_TXTBOX:
             case XOBJ_DTYPE_URL:
                 $type = "varchar";
                 // varchars must have a maxlength
                 if (!$maxlengthstring) {
                     //so set it to max if maxlength is not set - or should it fail?
                     $maxlengthstring = "(255)";
                     $obj->setVar('field_maxlength', 255);
                 }
                 break;
             case XOBJ_DTYPE_INT:
                 $type = "int";
                 break;
             case XOBJ_DTYPE_DECIMAL:
                 $type = "decimal(14,6)";
                 break;
             case XOBJ_DTYPE_FLOAT:
                 $type = "float(15,9)";
                 break;
             case XOBJ_DTYPE_OTHER:
             case XOBJ_DTYPE_UNICODE_TXTAREA:
             case XOBJ_DTYPE_TXTAREA:
                 $type = "text";
                 $maxlengthstring = "";
                 break;
             case XOBJ_DTYPE_MTIME:
                 $type = "date";
                 $maxlengthstring = "";
                 break;
         }
         $sql = "ALTER TABLE `" . $profile_handler->table . "` " . $changetype . " `" . $obj->cleanVars['field_name'] . "` " . $type . $maxlengthstring . ' NULL';
         if (!$this->db->query($sql)) {
             return false;
         }
     }
     //change this to also update the cached field information storage
     $obj->setDirty();
     if (!parent::insert($obj, $force)) {
         return false;
     }
     return $obj->getVar('field_id');
 }
Esempio n. 7
0
 /**
  * insert a new field in the database
  *
  * @param XoopsObject $field reference to the {@link TDMCreateFields} object
  * @param bool   $force
  *
  * @return bool FALSE if failed, TRUE if already present and unchanged or successful
  */
 public function insert(XoopsObject $field, $force = false)
 {
     if (!parent::insert($field, $force)) {
         return false;
     }
     return true;
 }
Esempio n. 8
0
 /**
  * insert a new category in the database
  *
  * @param object $category reference to the {@link PublisherCategory} object
  * @param bool   $force
  *
  * @return bool FALSE if failed, TRUE if already present and unchanged or successful
  */
 public function insert(&$category, $force = false)
 {
     // Auto create meta tags if empty
     if (!$category->meta_keywords() || !$category->meta_description()) {
         $publisherMetagen = new PublisherMetagen($category->name(), $category->getVar('meta_keywords'), $category->getVar('description'));
         if (!$category->meta_keywords()) {
             $category->setVar('meta_keywords', $publisherMetagen->keywords);
         }
         if (!$category->meta_description()) {
             $category->setVar('meta_description', $publisherMetagen->description);
         }
     }
     // Auto create short_url if empty
     if (!$category->short_url()) {
         $category->setVar('short_url', PublisherMetagen::generateSeoTitle($category->name('n'), false));
     }
     $ret = parent::insert($category, $force);
     return $ret;
 }
Esempio n. 9
0
 /**
  * insert a new object in the database
  *
  * @param object $obj reference to the object
  * @param bool $force whether to force the query execution despite security settings
  * @param bool $checkObject check if the object is dirty and clean the attributes
  *
  * @return bool FALSE if failed, TRUE if already present and unchanged or successful
  */
 function insert(&$obj, $force = false, $checkObject = true)
 {
     $uservars = $this->getUserVars();
     foreach ($uservars as $var) {
         unset($obj->vars[$var]);
     }
     if (count($obj->vars) == 0) {
         return true;
     }
     return parent::insert($obj, $force, $checkObject);
 }
Esempio n. 10
0
 /**
  * @param XoopsObject|ArtObject $object
  * @param bool                  $force
  *
  * @return mixed
  */
 public function insert(XoopsObject $object, $force = true)
 {
     if (!$object instanceof $this->className) {
         return false;
     }
     if ($ret = parent::insert($object, $force)) {
         $object->unsetNew();
     }
     return $ret;
 }
Esempio n. 11
0
 /**
  * save a profile field in the database
  *
  * @param XoopsObject|ProfileField $obj   reference to the object
  * @param bool                     $force whether to force the query execution despite security settings
  *
  * @internal param bool $checkObject check if the object is dirty and clean the attributes
  * @return bool FALSE if failed, TRUE if already present and unchanged or successful
  */
 public function insert(XoopsObject $obj, $force = false)
 {
     if (!$obj instanceof $this->className) {
         return false;
     }
     $profile_handler = xoops_getModuleHandler('profile', 'profile');
     $obj->setVar('field_name', str_replace(' ', '_', $obj->getVar('field_name')));
     $obj->cleanVars();
     $defaultstring = '';
     switch ($obj->getVar('field_type')) {
         case 'datetime':
         case 'date':
             $obj->setVar('field_valuetype', XOBJ_DTYPE_INT);
             $obj->setVar('field_maxlength', 10);
             break;
         case 'longdate':
             $obj->setVar('field_valuetype', XOBJ_DTYPE_MTIME);
             break;
         case 'yesno':
             $obj->setVar('field_valuetype', XOBJ_DTYPE_INT);
             $obj->setVar('field_maxlength', 1);
             break;
         case 'textbox':
             if ($obj->getVar('field_valuetype') != XOBJ_DTYPE_INT) {
                 $obj->setVar('field_valuetype', XOBJ_DTYPE_TXTBOX);
             }
             break;
         case 'autotext':
             if ($obj->getVar('field_valuetype') != XOBJ_DTYPE_INT) {
                 $obj->setVar('field_valuetype', XOBJ_DTYPE_TXTAREA);
             }
             break;
         case 'group_multi':
         case 'select_multi':
         case 'checkbox':
             $obj->setVar('field_valuetype', XOBJ_DTYPE_ARRAY);
             break;
         case 'language':
         case 'timezone':
         case 'theme':
             $obj->setVar('field_valuetype', XOBJ_DTYPE_TXTBOX);
             break;
         case 'dhtml':
         case 'textarea':
             $obj->setVar('field_valuetype', XOBJ_DTYPE_TXTAREA);
             break;
     }
     if ($obj->getVar('field_valuetype') === '') {
         $obj->setVar('field_valuetype', XOBJ_DTYPE_TXTBOX);
     }
     if (!in_array($obj->getVar('field_name'), $this->getUserVars()) && isset($_REQUEST['field_required'])) {
         if ($obj->isNew()) {
             //add column to table
             $changetype = 'ADD';
         } else {
             //update column information
             $changetype = 'CHANGE `' . $obj->getVar('field_name', 'n') . '`';
         }
         $maxlengthstring = $obj->getVar('field_maxlength') > 0 ? '(' . $obj->getVar('field_maxlength') . ')' : '';
         //set type
         switch ($obj->getVar('field_valuetype')) {
             default:
             case XOBJ_DTYPE_ARRAY:
             case XOBJ_DTYPE_UNICODE_ARRAY:
                 $type = 'mediumtext';
                 break;
             case XOBJ_DTYPE_UNICODE_EMAIL:
             case XOBJ_DTYPE_UNICODE_TXTBOX:
             case XOBJ_DTYPE_UNICODE_URL:
             case XOBJ_DTYPE_EMAIL:
             case XOBJ_DTYPE_TXTBOX:
             case XOBJ_DTYPE_URL:
                 $type = 'varchar';
                 // varchars must have a maxlength
                 if (!$maxlengthstring) {
                     //so set it to max if maxlength is not set - or should it fail?
                     $maxlengthstring = '(255)';
                     $obj->setVar('field_maxlength', 255);
                 }
                 break;
             case XOBJ_DTYPE_INT:
                 $type = 'int';
                 break;
             case XOBJ_DTYPE_DECIMAL:
                 $type = 'decimal(14,6)';
                 break;
             case XOBJ_DTYPE_FLOAT:
                 $type = 'float(15,9)';
                 break;
             case XOBJ_DTYPE_OTHER:
             case XOBJ_DTYPE_UNICODE_TXTAREA:
             case XOBJ_DTYPE_TXTAREA:
                 $type = 'text';
                 $maxlengthstring = '';
                 break;
             case XOBJ_DTYPE_MTIME:
                 $type = 'date';
                 $maxlengthstring = '';
                 break;
         }
         $sql = 'ALTER TABLE `' . $profile_handler->table . '` ' . $changetype . ' `' . $obj->cleanVars['field_name'] . '` ' . $type . $maxlengthstring . ' NULL';
         $result = $force ? $this->db->queryF($sql) : $this->db->query($sql);
         if (!$result) {
             return false;
         }
     }
     //change this to also update the cached field information storage
     $obj->setDirty();
     if (!parent::insert($obj, $force)) {
         return false;
     }
     return $obj->getVar('field_id');
 }
Esempio n. 12
0
 function setRead_db($read_item, $post_id, $uid)
 {
     if (empty($uid)) {
         if (is_object($GLOBALS["xoopsUser"])) {
             $uid = $GLOBALS["xoopsUser"]->getVar("uid");
         } else {
             return false;
         }
     }
     $sql = "UPDATE " . $this->table . " SET post_id = " . intval($post_id) . "," . "     read_time =" . time() . " WHERE read_item = " . intval($read_item) . "     AND uid = " . intval($uid);
     if ($this->db->queryF($sql) && $this->db->getAffectedRows()) {
         return true;
     }
     $object =& $this->create();
     $object->setVar("read_item", $read_item, true);
     $object->setVar("post_id", $post_id, true);
     $object->setVar("uid", $uid, true);
     $object->setVar("read_time", time(), true);
     return parent::insert($object);
 }
Esempio n. 13
0
 /**
  * insert a new object in the database
  *
  * @param XoopsObject|ProfileProfile $obj   reference to the object
  * @param bool                       $force whether to force the query execution despite security settings
  *
  * @return bool FALSE if failed, TRUE if already present and unchanged or successful
  */
 public function insert(\Xoops\Core\Kernel\XoopsObject $obj, $force = false)
 {
     $uservars = $this->getUserVars();
     foreach ($uservars as $var) {
         unset($obj->vars[$var]);
     }
     if (count($obj->vars) == 0) {
         return true;
     }
     return parent::insert($obj, $force);
 }
Esempio n. 14
0
 /**
  * @param XoopsObject|SystemBlock $obj
  *
  * @return int|bool object id on success, otherwise false
  */
 public function insert(XoopsObject $obj, $force = true)
 {
     if (!$obj instanceof $this->className) {
         return false;
     }
     $obj->setVar('last_modified', time());
     return parent::insert($obj, $force);
 }
Esempio n. 15
0
 function insert(&$object, $force = true)
 {
     if (!$object->getVar("topic_time")) {
         $object->setVar("topic_time", time());
     }
     if (!parent::insert($object, $force) || !$object->getVar("approved")) {
         return $object->getVar("topic_id");
     }
     require_once XOOPS_ROOT_PATH . "/modules/newbb/include/functions.config.php";
     $newbbConfig = newbb_loadConfig();
     if (!empty($newbbConfig['do_tag']) && @(include_once XOOPS_ROOT_PATH . "/modules/tag/include/functions.php")) {
         if ($tag_handler = tag_getTagHandler()) {
             $tag_handler->updateByItem($object->getVar('topic_tags', 'n'), $object->getVar('topic_id'), "newbb");
         }
     }
     return $object->getVar("topic_id");
 }
Esempio n. 16
0
 /**
  * insert a new user in the database
  * 
  * @param object $user reference to the {@link XoopsUser} object
  * @param bool $force
  * @return bool FALSE if failed, TRUE if already present and unchanged or successful
  */
 function insert(&$user, $force = false)
 {
     if (!parent::insert($user, $force)) {
         return false;
     }
     $profile = $user->getProfile();
     $profile->setVar('profileid', $user->getVar('uid'));
     // save profile
     if (!$this->_pHandler->insert($profile, $force)) {
         foreach ($profile->getErrors() as $error) {
             $user->setErrors($error);
         }
         return false;
     }
     return true;
 }
Esempio n. 17
0
 /**
  * Write a module to the database
  * 
  * @param   object  &$module reference to a {@link XoopsModule} 
  * @return  bool
  **/
 function insert(&$module)
 {
     if (!parent::insert($module)) {
         return false;
     }
     if (!empty($this->_cachedModule_dirname[$module->getVar('dirname')])) {
         unset($this->_cachedModule_dirname[$module->getVar('dirname')]);
     }
     if (!empty($this->_cachedModule_mid[$module->getVar('mid')])) {
         unset($this->_cachedModule_mid[$module->getVar('mid')]);
     }
     return true;
 }
Esempio n. 18
0
 /**
  * insert a new object in the database
  *
  * @param XoopsObject|ProfileProfile $obj   reference to the object
  * @param bool                       $force whether to force the query execution despite security settings
  *
  * @return bool FALSE if failed, TRUE if already present and unchanged or successful
  */
 public function insert(XoopsObject $obj, $force = false)
 {
     if (!$obj instanceof $this->className) {
         return false;
     }
     $uservars = $this->getUserVars();
     foreach ($uservars as $var) {
         unset($obj->vars[$var]);
     }
     if (count($obj->vars) == 0) {
         return true;
     }
     return parent::insert($obj, $force);
 }
Esempio n. 19
0
 function insert(&$digest)
 {
     return parent::insert($digest);
     /*
     $content = $digest->getVar('digest_content', 'E');
     
     $id = $this->db->genId($digest->table . "_digest_id_seq");
     $sql = "INSERT INTO " . $digest->table . " (digest_id, digest_time, digest_content)    VALUES (" . $id . ", " . time() . ", " . $this->db->quoteString($content) . " )";
     
     if (!$this->db->queryF($sql)) {
     //echo "<br />digest insert error::" . $sql;
     return false;
     }
     if (empty($id)) {
     $id = $this->db->getInsertId();
     }
     $digest->setVar('digest_id', $id);
     return true;
     */
 }
Esempio n. 20
0
 /**
  * save a profile field in the database
  *
  * @param object $obj reference to the object
  * @param bool $force whether to force the query execution despite security settings
  * @param bool $checkObject check if the object is dirty and clean the attributes
  * @return bool FALSE if failed, TRUE if already present and unchanged or successful
  */
 function insert(&$obj, $force = false)
 {
     $profile_handler =& xoops_gethandler('profile');
     if ($obj->isNew()) {
         //add column to table
         $changetype = "ADD";
     } else {
         //update column information
         $changetype = "CHANGE " . $obj->getVar('field_name', 'n');
     }
     $obj->cleanVars();
     $defaultstring = "";
     switch ($obj->getVar('field_type')) {
         case "datetime":
         case "date":
             $obj->setVar('field_valuetype', XOBJ_DTYPE_INT);
             $obj->setVar('field_maxlength', 10);
             break;
             //            case "longdate":
             //                $obj->setVar('field_valuetype', XOBJ_DTYPE_TXTBOX);
             //                break;
         //            case "longdate":
         //                $obj->setVar('field_valuetype', XOBJ_DTYPE_TXTBOX);
         //                break;
         case "yesno":
             $obj->setVar('field_valuetype', XOBJ_DTYPE_INT);
             $obj->setVar('field_maxlength', 1);
             break;
         case "textbox":
             if ($obj->getVar('field_valuetype') != XOBJ_DTYPE_INT) {
                 //$obj->setVar('field_valuetype', XOBJ_DTYPE_TXTBOX);
             }
             break;
         case "autotext":
             if ($obj->getVar('field_valuetype') != XOBJ_DTYPE_INT) {
                 $obj->setVar('field_valuetype', XOBJ_DTYPE_TXTAREA);
             }
             break;
         case "group_multi":
         case "select_multi":
         case "checkbox":
             $obj->setVar('field_valuetype', XOBJ_DTYPE_ARRAY);
             break;
         case "language":
         case "timezone":
         case "theme":
             $obj->setVar('field_valuetype', XOBJ_DTYPE_TXTBOX);
             break;
         case "dhtml":
         case "textarea":
             $obj->setVar('field_valuetype', XOBJ_DTYPE_TXTAREA);
             break;
     }
     if ($obj->getVar('field_valuetype') == "") {
         $obj->setVar('field_valuetype', XOBJ_DTYPE_TXTBOX);
     }
     //set type
     switch ($obj->getVar('field_valuetype')) {
         default:
         case XOBJ_DTYPE_ARRAY:
         case XOBJ_DTYPE_EMAIL:
         case XOBJ_DTYPE_TXTBOX:
         case XOBJ_DTYPE_URL:
             $type = "varchar";
             // varchars must have a maxlength
             if (!($obj->getVar('field_maxlength') > 0)) {
                 //so set it to max if maxlength is not set - or should it fail?
                 $obj->setVar('field_maxlength', 255);
             }
             if ($obj->getVar('field_default')) {
                 $defaultstring = " DEFAULT " . $this->db->quoteString($obj->cleanVars['field_default']);
             }
             break;
         case XOBJ_DTYPE_INT:
             $type = "int";
             if ($obj->getVar('field_default')) {
                 $defaultstring = " DEFAULT " . $this->db->quoteString($obj->cleanVars['field_default']);
             }
             break;
         case XOBJ_DTYPE_OTHER:
         case XOBJ_DTYPE_TXTAREA:
             $type = "text";
             break;
     }
     $maxlengthstring = $obj->getVar('field_maxlength') > 0 ? "(" . $obj->getVar('field_maxlength') . ")" : "";
     $notnullstring = " NOT NULL";
     $sql = "ALTER TABLE " . $profile_handler->table . " " . $changetype . " " . $obj->cleanVars['field_name'] . " " . $type . $maxlengthstring . $notnullstring . $defaultstring;
     if ($this->db->query($sql)) {
         //change this to also update the cached field information storage
         $obj->setDirty();
         if (!parent::insert($obj, $force)) {
             return false;
         }
         if ($obj->getVar('field_show') || $obj->getVar('field_edit')) {
             $module_handler =& xoops_gethandler('module');
             $profile_module =& $module_handler->getByDirname('profile');
             if (is_object($profile_module)) {
                 // Add group permissions
                 $groupperm_handler =& xoops_gethandler('groupperm');
                 if ($obj->getVar('field_show')) {
                     $groupperm_handler->addRight('profile_show', $obj->getVar('fieldid'), XOOPS_GROUP_USERS, $profile_module->getVar('mid'));
                 }
                 if ($obj->getVar('field_edit')) {
                     $groupperm_handler->addRight('profile_edit', $obj->getVar('fieldid'), XOOPS_GROUP_USERS, $profile_module->getVar('mid'));
                 }
             }
         }
         //Update cached field information storage:
         $this->updateCache();
         return true;
     }
     return false;
 }
Esempio n. 21
0
 /**
  * insert a new item in the database
  *
  * @param object $item reference to the {@link PublisherItem} object
  * @param bool   $force
  *
  * @return bool FALSE if failed, TRUE if already present and unchanged or successful
  */
 public function insert(&$item, $force = false)
 {
     if (!$item->meta_keywords() || !$item->meta_description() || !$item->short_url()) {
         $publisher_metagen = new PublisherMetagen($item->title(), $item->getVar('meta_keywords'), $item->getVar('summary'));
         // Auto create meta tags if empty
         if (!$item->meta_keywords()) {
             $item->setVar('meta_keywords', $publisher_metagen->_keywords);
         }
         if (!$item->meta_description()) {
             $item->setVar('meta_description', $publisher_metagen->_description);
         }
         // Auto create short_url if empty
         if (!$item->short_url()) {
             $item->setVar('short_url', $publisher_metagen->generateSeoTitle($item->getVar('title', 'n'), false));
         }
     }
     if (!parent::insert($item, $force)) {
         return false;
     }
     if (xoops_isActiveModule('tag')) {
         // Storing tags information
         $tag_handler = xoops_getmodulehandler('tag', 'tag');
         $tag_handler->updateByItem($item->getVar('item_tag'), $item->getVar('itemid'), PUBLISHER_DIRNAME, 0);
     }
     return true;
 }
Esempio n. 22
0
 function insert(&$post, $force = true)
 {
     global $xoopsUser;
     // Set the post time
     // The time should be "publish" time. To be adjusted later
     if (!$post->getVar("post_time")) {
         $post->setVar("post_time", time());
     }
     $topic_handler =& xoops_getmodulehandler("topic", "newbb");
     // Verify the topic ID
     if ($topic_id = $post->getVar("topic_id")) {
         $topic_obj =& $topic_handler->get($topic_id);
         // Invalid topic OR the topic is no approved and the post is not top post
         if (!$topic_obj) {
             return false;
         }
     }
     if (empty($topic_id)) {
         $post->setVar("topic_id", 0);
         $post->setVar("pid", 0);
         $post->setNew();
         $topic_obj =& $topic_handler->create();
     }
     $text_handler =& xoops_getmodulehandler("text", "newbb");
     $post_text_vars = array("post_text", "post_edit", "dohtml", "doxcode", "dosmiley", "doimage", "dobr");
     if ($post->isNew()) {
         if (!($topic_id = $post->getVar("topic_id"))) {
             $topic_obj->setVar("topic_title", $post->getVar("subject", "n"));
             $topic_obj->setVar("topic_poster", $post->getVar("uid"));
             $topic_obj->setVar("forum_id", $post->getVar("forum_id"));
             $topic_obj->setVar("topic_time", $post->getVar("post_time"));
             $topic_obj->setVar("poster_name", $post->getVar("poster_name"), true);
             $topic_obj->setVar("approved", $post->getVar("approved"), true);
             if (!($topic_id = $topic_handler->insert($topic_obj, $force))) {
                 $post->deleteAttachment();
                 $post->setErrors("insert topic error");
                 return false;
             }
             $post->setVar('topic_id', $topic_id);
             $pid = 0;
             $post->setVar("pid", 0);
         } elseif (!$post->getVar("pid")) {
             $pid = $topic_handler->getTopPostId($topic_id);
             $post->setVar("pid", $pid);
         }
         $text_obj =& $text_handler->create();
         foreach ($post_text_vars as $key) {
             $text_obj->vars[$key] = $post->vars[$key];
         }
         $post->destoryVars($post_text_vars);
         if (!($post_id = parent::insert($post, $force))) {
             return false;
         }
         $text_obj->setVar("post_id", $post_id);
         if (!$text_handler->insert($text_obj, $force)) {
             $this->delete($post);
             $post->setErrors("post text insert error");
             return false;
         }
         if ($post->getVar("approved") > 0) {
             $this->approve($post, true);
         }
         $post->setVar('post_id', $post_id);
     } else {
         if ($post->isTopic()) {
             if ($post->getVar("subject") != $topic_obj->getVar("topic_title")) {
                 $topic_obj->setVar("topic_title", $post->getVar("subject", "n"));
             }
             if ($post->getVar("approved") != $topic_obj->getVar("approved")) {
                 $topic_obj->setVar("approved", $post->getVar("approved"));
             }
             if (!($result = $topic_handler->insert($topic_obj, $force))) {
                 $post->setErrors("update topic error");
                 return false;
             }
         }
         $text_obj =& $text_handler->get($post->getVar("post_id"));
         $text_obj->setDirty();
         foreach ($post_text_vars as $key) {
             $text_obj->vars[$key] = $post->vars[$key];
         }
         $post->destoryVars($post_text_vars);
         if (!($post_id = parent::insert($post, $force))) {
             return false;
         }
         if (!$text_handler->insert($text_obj, $force)) {
             $post->setErrors("update post text error");
             return false;
         }
     }
     return $post->getVar('post_id');
 }