Exemplo n.º 1
0
 /**
  * cleanVar prepare variable for persistence
  *
  * @param XoopsObject $obj object containing variable
  * @param string      $key name of variable
  *
  * @return string
  */
 public function cleanVar(XoopsObject $obj, $key)
 {
     $value = $obj->vars[$key]['value'];
     if (!in_array($value, $obj->vars[$key]['enumeration'])) {
         $obj->setErrors("Invalid Enumeration");
         return $value;
     }
     return $value;
 }
Exemplo n.º 2
0
 /**
  * cleanVar prepare variable for persistence
  *
  * @param XoopsObject $obj object containing variable
  * @param string      $key name of variable
  *
  * @return string
  */
 public function cleanVar(XoopsObject $obj, $key)
 {
     $value = $obj->vars[$key]['value'];
     if ($obj->vars[$key]['required'] && $value != '0' && $value == '') {
         $obj->setErrors(sprintf(\XoopsLocale::F_IS_REQUIRED, $key));
         return $value;
     }
     $value = $this->ts->censorString($value);
     return $value;
 }
Exemplo n.º 3
0
 /**
  * @param XoopsObject $obj
  * @param string      $key
  * @param bool        $quote
  *
  * @return string
  */
 public function cleanVar(XoopsObject $obj, $key, $quote = true)
 {
     $value = $obj->vars[$key]['value'];
     if (!in_array($value, $obj->vars[$key]['enumeration'])) {
         $obj->setErrors("Invalid Enumeration");
         return $value;
     }
     if ($quote) {
         $value = str_replace('\\"', '"', $this->db->quote($value));
     }
     return $value;
 }
Exemplo n.º 4
0
 /**
  * cleanVar prepare variable for persistence
  *
  * @param XoopsObject $obj object containing variable
  * @param string      $key name of variable
  *
  * @return string
  */
 public function cleanVar(XoopsObject $obj, $key)
 {
     $value = trim($obj->vars[$key]['value']);
     if ($obj->vars[$key]['required'] && $value == '') {
         $obj->setErrors(sprintf(\XoopsLocale::F_IS_REQUIRED, $key));
         return $value;
     }
     if ($value != '' && !preg_match("/^http[s]*:\\/\\//i", $value)) {
         $value = 'http://' . $value;
     }
     return $value;
 }
Exemplo n.º 5
0
 /**
  * cleanVar prepare variable for persistence
  *
  * @param XoopsObject $obj object containing variable
  * @param string      $key name of variable
  *
  * @return string
  */
 public function cleanVar(XoopsObject $obj, $key)
 {
     $value = trim($obj->vars[$key]['value']);
     if ($obj->vars[$key]['required'] && $value == '') {
         $obj->setErrors(sprintf(\XoopsLocale::F_IS_REQUIRED, $key));
         return $value;
     }
     if ($value != '' && !preg_match("/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+([\\.][a-z0-9-]+)+\$/i", $value)) {
         $obj->setErrors("Invalid Email");
         return $value;
     }
     return $value;
 }
Exemplo n.º 6
0
 /**
  * Clean values of all variables of the object for storage.
  * also add slashes and quote string wherever needed
  *
  * @param XoopsObject $object object to act on
  *
  * @return bool true if successful
  * @access public
  */
 public function cleanVars(XoopsObject $object)
 {
     $vars = $object->getVars();
     $object->cleanVars = array();
     foreach ($vars as $k => $v) {
         if (!$v["changed"]) {
             continue;
         }
         $object->cleanVars[$k] = Dtype::cleanVar($object, $k);
     }
     $object->unsetDirty();
     $errors = $object->getErrors();
     return empty($errors) ? true : false;
 }
Exemplo n.º 7
0
 /**
  * cleanVar prepare variable for persistence
  *
  * @param XoopsObject $obj object containing variable
  * @param string      $key name of variable
  *
  * @return string
  */
 public function cleanVar(XoopsObject $obj, $key)
 {
     $value = $obj->vars[$key]['value'];
     if ($obj->vars[$key]['required'] && $value != '0' && $value == '') {
         $obj->setErrors(sprintf(\XoopsLocale::F_IS_REQUIRED, $key));
         return $value;
     }
     if (isset($obj->vars[$key]['maxlength']) && mb_strlen($value) > (int) $obj->vars[$key]['maxlength']) {
         $obj->setErrors(sprintf(\XoopsLocale::F_MUST_BE_SHORTER_THAN, $key, (int) $obj->vars[$key]['maxlength']));
         return $value;
     }
     $value = $this->ts->censorString($value);
     return $value;
 }
Exemplo n.º 8
0
 public function getValues($keys = null, $format = null, $maxDepth = null)
 {
     $ret = parent::getValues($keys, $format, $maxDepth);
     $ret['navigation'] = Xoops_Locale::translate('L_RELATED_NAVIGATION_OPTION' . $this->getVar('related_navigation'), 'page');
     $ret['related_links'] = Page::getInstance()->getLinkHandler()->getLinks($this->getVar('related_id'));
     return $ret;
 }
Exemplo n.º 9
0
 /**
  * @param XoopsObject $obj
  * @param string      $key
  * @param bool        $quote
  *
  * @return string
  */
 public function cleanVar(XoopsObject $obj, $key, $quote = true)
 {
     $value = $obj->vars[$key]['value'];
     if ($obj->vars[$key]['required'] && $value != '0' && $value == '') {
         $obj->setErrors(sprintf(\XoopsLocale::F_IS_REQUIRED, $key));
         return $value;
     }
     if (!$obj->vars[$key]['not_gpc']) {
         $value = $this->ts->stripSlashesGPC($this->ts->censorString($value));
     } else {
         $value = $this->ts->censorString($value);
     }
     if ($quote) {
         $value = str_replace('\\"', '"', $this->db->quote($value));
     }
     return $value;
 }
Exemplo n.º 10
0
 /**
  * @param XoopsObject $obj
  * @param string      $key
  * @param bool        $quote
  *
  * @return string
  */
 function cleanVar(XoopsObject $obj, $key, $quote = true)
 {
     $value = trim($obj->vars[$key]['value']);
     if ($obj->vars[$key]['required'] && $value == '') {
         $obj->setErrors(sprintf(\XoopsLocale::F_IS_REQUIRED, $key));
         return $value;
     }
     if ($value != '' && !preg_match("/^http[s]*:\\/\\//i", $value)) {
         $value = 'http://' . $value;
     }
     if (!$obj->vars[$key]['not_gpc']) {
         $value = $this->ts->stripSlashesGPC($value);
     }
     if ($quote) {
         $value = str_replace('\\"', '"', $this->db->quote($value));
     }
     return $value;
 }
Exemplo n.º 11
0
 /**
  * @param XoopsObject $obj
  * @param string      $key
  * @param bool        $quote
  *
  * @return string
  */
 public function cleanVar(XoopsObject $obj, $key, $quote = true)
 {
     $value = trim($obj->vars[$key]['value']);
     if ($obj->vars[$key]['required'] && $value == '') {
         $obj->setErrors(sprintf(\XoopsLocale::F_IS_REQUIRED, $key));
         return $value;
     }
     if ($value != '' && !preg_match("/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+([\\.][a-z0-9-]+)+\$/i", $value)) {
         $obj->setErrors("Invalid Email");
         return $value;
     }
     if (!$obj->vars[$key]['not_gpc']) {
         $value = $this->ts->stripSlashesGPC($value);
     }
     if ($quote) {
         $value = str_replace('\\"', '"', $this->db->quote($value));
     }
     return $value;
 }
Exemplo n.º 12
0
 public function cleanVarsForDB()
 {
     $system = System::getInstance();
     foreach (parent::getValues() as $k => $v) {
         if ($k !== 'dohtml') {
             if ($this->vars[$k]['data_type'] == XOBJ_DTYPE_STIME || $this->vars[$k]['data_type'] == XOBJ_DTYPE_MTIME || $this->vars[$k]['data_type'] == XOBJ_DTYPE_LTIME) {
                 $value = $system->cleanVars($_POST[$k], 'date', date('Y-m-d'), 'date') + $system->cleanVars($_POST[$k], 'time', date('u'), 'int');
                 $this->setVar($k, isset($_POST[$k]) ? $value : $v);
             } elseif ($this->vars[$k]['data_type'] == XOBJ_DTYPE_INT) {
                 $value = $system->cleanVars($_POST, $k, $v, 'int');
                 $this->setVar($k, $value);
             } elseif ($this->vars[$k]['data_type'] == XOBJ_DTYPE_ARRAY) {
                 $value = $system->cleanVars($_POST, $k, $v, 'array');
                 $this->setVar($k, $value);
             } else {
                 $value = $system->cleanVars($_POST, $k, $v, 'string');
                 $this->setVar($k, $value);
             }
         }
     }
 }
Exemplo n.º 13
0
 /**
  * delete a file from the database
  *
  * @param XoopsObject|PublisherFile $file reference to the file to delete
  * @param bool   $force
  *
  * @return bool FALSE if failed.
  */
 public function delete(XoopsObject $file, $force = false)
 {
     $ret = false;
     // Delete the actual file
     if (is_file($file->getFilePath()) && unlink($file->getFilePath())) {
         $ret = parent::delete($file, $force);
     }
     return $ret;
 }
Exemplo n.º 14
0
 public function toArray()
 {
     $ret = parent::getValues();
     unset($ret['dohtml']);
     return $ret;
 }
Exemplo n.º 15
0
 /**
  * delete a profile field from the database
  *
  * @param XoopsObject|ProfileField $obj reference to the object to delete
  * @param bool $force
  * @return bool FALSE if failed.
  **/
 public function deleteFields(XoopsObject $obj, $force = false)
 {
     $xoops = Xoops::getInstance();
     $profile_handler = \Xoops::getModuleHelper('profile')->getHandler('profile');
     // remove column from table
     $sql = "ALTER TABLE " . $profile_handler->table . " DROP `" . $obj->getVar('field_name', 'n') . "`";
     if ($this->db2->query($sql)) {
         //change this to update the cached field information storage
         if (!parent::delete($obj, $force)) {
             return false;
         }
         if ($obj->getVar('field_show') || $obj->getVar('field_edit')) {
             $profile_module = $xoops->getModuleByDirname('profile');
             if (is_object($profile_module)) {
                 // Remove group permissions
                 $groupperm_handler = $xoops->getHandlerGroupPermission();
                 $criteria = new CriteriaCompo(new Criteria('gperm_modid', $profile_module->getVar('mid')));
                 $criteria->add(new Criteria('gperm_itemid', $obj->getVar('field_id')));
                 return $groupperm_handler->deleteAll($criteria);
             }
         }
     }
     return false;
 }
Exemplo n.º 16
0
 /**
  * delete a category from the database
  *
  * @param XoopsObject $category reference to the category to delete
  * @param bool        $force
  *
  * @return bool FALSE if failed.
  */
 public function delete(XoopsObject $category, $force = false)
 {
     $xoops = Xoops::getInstance();
     // Deleting this category ITEMs
     $criteria = new Criteria('categoryid', $category->getVar('categoryid'));
     $this->publisher->getItemHandler()->deleteAll($criteria, true, true);
     unset($criteria);
     // Deleting the sub categories
     $subcats = $this->getCategories(0, 0, $category->getVar('categoryid'));
     foreach ($subcats as $subcat) {
         $this->delete($subcat);
     }
     if (!parent::delete($category, $force)) {
         $category->setErrors('An error while deleting.');
         return false;
     }
     $module_id = $this->publisher->getModule()->getVar('mid');
     $xoops->getHandlerGroupPermission()->deleteByModule($module_id, "category_read", $category->getVar('categoryid'));
     $xoops->getHandlerGroupPermission()->deleteByModule($module_id, "item_submit", $category->getVar('categoryid'));
     $xoops->getHandlerGroupPermission()->deleteByModule($module_id, "category_moderation", $category->getVar('categoryid'));
     return true;
 }
Exemplo n.º 17
0
 /**
  * insert a new item in the database
  *
  * @param XoopsObject $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(XoopsObject $item, $force = true)
 {
     $xoops = Xoops::getInstance();
     if (!$item->getVar('meta_keywords') || !$item->getVar('meta_description') || !$item->getVar('short_url')) {
         $publisher_metagen = new PublisherMetagen($item->title(), $item->getVar('meta_keywords'), $item->getVar('summary'));
         // Auto create meta tags if empty
         if (!$item->getVar('meta_keywords')) {
             $item->setVar('meta_keywords', $publisher_metagen->_keywords);
         }
         if (!$item->getVar('meta_description')) {
             $item->setVar('meta_description', $publisher_metagen->_description);
         }
         // Auto create short_url if empty
         if (!$item->getVar('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;
 }
Exemplo n.º 18
0
 /**
  * @param UserrankRank|XoopsObject $obj
  */
 public function __construct(XoopsObject $obj)
 {
     $xoops = \Xoops::getInstance();
     if ($obj->isNew()) {
         $blank_img = 'blank.gif';
     } else {
         $blank_img = str_replace('ranks/', '', $obj->getVar('rank_image', 'e'));
     }
     $title = $obj->isNew() ? sprintf(_AM_USERRANK_ADD) : sprintf(_AM_USERRANK_EDIT);
     parent::__construct($title, 'form', 'userrank.php', 'post', true);
     $this->setExtra('enctype="multipart/form-data"');
     $this->addElement(new Xoops\Form\Text(_AM_USERRANK_TITLE, 'rank_title', 4, 50, $obj->getVar('rank_title')), true);
     $min = new Xoops\Form\Text(_AM_USERRANK_MINPOST, 'rank_min', 1, 10, $obj->getVar('rank_min'));
     $min->setPattern('^\\d+$', _AM_USERRANK_ERROR_POST);
     $this->addElement($min);
     $max = new Xoops\Form\Text(_AM_USERRANK_MAXPOST, 'rank_max', 1, 10, $obj->getVar('rank_max'));
     $max->setPattern('^\\d+$', _AM_USERRANK_ERROR_POST);
     $this->addElement($max);
     $imgtray_img = new Xoops\Form\ElementTray(_AM_USERRANK_IMAGE, '<br />');
     $imgpath_img = sprintf(_AM_USERRANK_IMAGE_PATH, $xoops->path('uploads/ranks/'));
     $imageselect_img = new Xoops\Form\Select($imgpath_img, 'rank_image', $blank_img);
     $imageselect_img->addOption($blank_img, $blank_img);
     \Xoops\Core\Lists\ImageFile::setOptionsArray($imageselect_img, $xoops->path('uploads/ranks'));
     $imageselect_img->setExtra("onchange='showImgSelected(\"xo-ranks-img\", \"rank_image\", \"ranks\", \"\", \"" . \XoopsBaseConfig::get('uploads-url') . "\")'");
     $imgtray_img->addElement($imageselect_img, false);
     $imgtray_img->addElement(new Xoops\Form\Label('', "<br /><img src='" . \XoopsBaseConfig::get('uploads-url') . "/ranks/" . $blank_img . "' name='image_img' id='xo-ranks-img' alt='' />"));
     $fileseltray_img = new Xoops\Form\ElementTray('<br />', '<br /><br />');
     $fileseltray_img->addElement(new Xoops\Form\File(_AM_USERRANK_UPLOAD, 'rank_image'), false);
     $fileseltray_img->addElement(new Xoops\Form\Label(''), false);
     $imgtray_img->addElement($fileseltray_img);
     $this->addElement($imgtray_img);
     if (!$obj->isNew()) {
         $rank_special = $obj->getVar('rank_special');
     } else {
         $rank_special = 0;
     }
     $special_tray = new Xoops\Form\ElementTray(_AM_USERRANK_SPECIAL, '<br />');
     $special_tray->setDescription(_AM_USERRANK_SPECIAL_CAN);
     $special_tray->addElement(new Xoops\Form\RadioYesNo('', 'rank_special', $rank_special));
     $this->addElement($special_tray);
     if (!$obj->isNew()) {
         $this->addElement(new Xoops\Form\Hidden('rank_id', $obj->getVar('rank_id')));
     }
     $this->addElement(new Xoops\Form\Hidden('op', 'userrank_save'));
     $this->addElement(new Xoops\Form\Button('', 'submit', XoopsLocale::A_SUBMIT, 'submit'));
 }
Exemplo n.º 19
0
 public function getValues($keys = null, $format = null, $maxDepth = null)
 {
     $ret = parent::getValues($keys, $format, $maxDepth);
     return $ret;
 }