public function type()
 {
     return getBaseName($this);
 }
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "inc" . DIRECTORY_SEPARATOR . "config.php";
$error = "";
if (CONFIG_SYS_VIEW_ONLY || !CONFIG_OPTIONS_DELETE) {
    $error = SYS_DISABLED;
} elseif (!empty($_GET['delete'])) {
    //delete the selected file from context menu
    if (!file_exists($_GET['delete'])) {
        $error = ERR_FILE_NOT_AVAILABLE;
    } elseif (!isUnderRoot($_GET['delete'])) {
        $error = ERR_FOLDER_PATH_NOT_ALLOWED;
    } else {
        include_once CLASS_FILE;
        $file = new file();
        if (is_dir($_GET['delete']) && isValidPattern(CONFIG_SYS_INC_DIR_PATTERN, getBaseName($_GET['delete'])) && !isInvalidPattern(CONFIG_SYS_EXC_DIR_PATTERN, getBaseName($_GET['delete']))) {
            $file->delete(addTrailingSlash(backslashToSlash($_GET['delete'])));
        } elseif (is_file($_GET['delete']) && isValidPattern(CONFIG_SYS_INC_FILE_PATTERN, getBaseName($_GET['delete'])) && !isInvalidPattern(CONFIG_SYS_EXC_FILE_PATTERN, getBaseName($_GET['delete']))) {
            $file->delete($_GET['delete']);
        }
    }
} else {
    if (!isset($_POST['selectedDoc']) || !is_array($_POST['selectedDoc']) || sizeof($_POST['selectedDoc']) < 1) {
        $error = ERR_NOT_FILE_SELECTED;
    } else {
        include_once CLASS_FILE;
        $file = new file();
        foreach ($_POST['selectedDoc'] as $doc) {
            if (file_exists($doc) && isUnderRoot($doc)) {
                if (is_dir($doc) && isValidPattern(CONFIG_SYS_INC_DIR_PATTERN, $doc) && !isInvalidPattern(CONFIG_SYS_EXC_DIR_PATTERN, $doc)) {
                    $file->delete(addTrailingSlash(backslashToSlash($doc)));
                } elseif (is_file($doc) && isValidPattern(CONFIG_SYS_INC_FILE_PATTERN, $doc) && !isInvalidPattern(CONFIG_SYS_EXC_FILE_PATTERN, $doc)) {
                    $file->delete($doc);
Example #3
0
 public static function tableFieldName()
 {
     $baseModel = getBaseName(static::class);
     $base = removeStartStr($baseModel, 'Ref');
     if (!$base) {
         return false;
     }
     $lcbase = strtolower($base);
     return $lcbase . '_ref';
 }
 /**
  * group operation alias method
  *
  * @param \Illuminate\Database\Eloquent\Model $model
  * @param string $subBase
  * @return boolean
  */
 protected function groupAlias($model, $subBase = 'Events')
 {
     $namespace = getBaseName($model, $subBase);
     $events = [];
     switch ($this->request->action) {
         case 'activate':
             $events['activationSuccess'] = \ErenMustafaOzdal\LaravelUserModule\Events\Auth\ActivateSuccess::class;
             $events['activationFail'] = \ErenMustafaOzdal\LaravelUserModule\Events\Auth\ActivateFail::class;
             break;
         case 'not_activate':
             $events['activationRemove'] = \ErenMustafaOzdal\LaravelUserModule\Events\Auth\ActivateRemove::class;
             $events['activationFail'] = \ErenMustafaOzdal\LaravelUserModule\Events\Auth\ActivateFail::class;
             break;
         case 'publish':
             $events['success'] = "{$namespace}\\PublishSuccess";
             $events['fail'] = "{$namespace}\\PublishFail";
             break;
         case 'not_publish':
             $events['success'] = "{$namespace}\\NotPublishSuccess";
             $events['fail'] = "{$namespace}\\NotPublishFail";
             break;
         case 'destroy':
             if ($model == 'App\\User' && in_array(Sentinel::getUser()->id, $this->request->get('id'))) {
                 abort(403);
             }
             break;
     }
     $this->setEvents($events);
     $action = camel_case($this->request->action) . 'GroupAction';
     return $this->{$action}($model);
 }
Example #5
0
/** Creates an HTML element or array of elements holding encoded PkModel attribute
 * data for use by JS on the page.
 * @param PkModel|arrayish PkModels - $pkmodels - the model(s) to get attributes
 * for. Can be mixed types - but then have to use the default model typename
 * @param string|null $typename - what to call the type in the element.
 *   Default is basename of the PkModel class.
 * @return HTML String|Array HTML Strings - elements in the form:
 *  <div class='encoded-data-holder' data-encoded-data-objtype="$typename"
 *   data-encoded-data-objid="$id" data-encoded-data-data="$encoded_data"></div>"
 */
function jsObjDataGen($pkmodels, $typename = null) {
  if ($pkmodels instanceOf \PkExtensions\Models\PkModel) {
    $pkmodels = [$pkmodels];
  }
  $tstInstance = $pkmodels[0];
  $typeof = typeOf($tstInstance);
  if (!$tstInstance instanceOf \PkExtensions\Models\PkModel) {
    throw new \Exception ("Wrong type: [$typeof]");
  }
  //if (!$typename) $typename = strtolower(getBaseName($typeof));
  $ps = new PartialSet();
  foreach ($pkmodels as $instance) {
    if (!$typename) $thistypename = strtolower(getBaseName(get_class($instance)));
    else $thistypename = $typename;
    $encdata = $instance->getEncodedCustomAttributes();
    $id = $instance->id;
    $ps[] = "<div class='encoded-data-holder' data-encoded-data-objtype='$thistypename'
       data-encoded-data-objid='$id' data-encoded-data-data='$encdata'></div>\n";
  }
  return $ps;

} 
Example #6
0
 /** This relies on the m-m definitions in the static $load_many_to_many array
  * Much more complicated than just saving one to many, or deleting many to many....
  * The daya should be an array that contains keys to the relationship matching
  * the relationship names defined in the object.
  * 
  * Like if this class has many-to-many relationships with items and
  * children, it should have those relationships defined in the class, and
  * also defined in the static::$load_many_to_many variable, with the key
  * names of $load_many_to_many the same as the relationship names
  */
 public function saveM2MRelations($data = [])
 {
     //pkdebug("Saving Here Data:", $data);
     if (empty(static::$load_many_to_many) || !array_intersect(array_keys(static::$load_many_to_many), array_keys($data))) {
         return true;
         #Nothing to do
     }
     foreach (static::$load_many_to_many as $relName => $definition) {
         if (!in_array($relName, array_keys($data))) {
             continue;
         }
         #Nothing here, keep looking
         $othermodel = keyval('other_model', $definition);
         if (!class_exists($othermodel) || !is_a($othermodel, self::class, true)) {
             throw new Exception("No found other class was defined for [{$relName}]");
         }
         #Have the 'other' class - now find Pivot Class or Table
         $pivotmodel = keyval('pivot_model', $definition);
         if (!class_exists($pivotmodel) || !is_a($pivotmodel, self::class, true)) {
             $pivotmodel = null;
             $pivottable = keyval('pivot_table', $definition);
             if (!Schema::hasTable($pivottable)) {
                 #Can't do anything
                 throw new Exception("Niether a valid pivot class nor tabe was defined for [{$relName}]");
             }
         }
         $mykey = keyval('my_key', $definition, Str::snake(getBaseName(static::class)) . '_id');
         $otherkey = keyval('other_key', $definition, Str::snake(getBaseName($othermodel)) . '_id');
         #Here's where the easy part ends.
         $arr = $data[$relName];
         if (!is_arrayish($arr) || !count($arr)) {
             #Delete it all!
             $deleteAll = true;
         } else {
             #We have an array of data
             $otherobjs = $this->{$relName};
             if (!is_arrayish($otherobjs)) {
                 pkdebug("unexpected for [{$relName}], other objs are:", $otherobjs);
                 continue;
             }
             $mycurrentotherobjkeys = [];
             foreach ($otherobjs as $otherobj) {
                 if (!is_a($otherobj, $othermodel, true)) {
                     #Again, something seriously wrong
                     pkdebug("For [{$relName}], other model is [{$othermodel}], but otherobj:", $otherobj);
                     continue;
                 }
                 $otherobjkey = $otherobj->getKey();
                 $mycurrentotherobjkeys[] = "{$otherobjkey}";
             }
             #Great - we have a list of otherobj keys our model pointed to, we have a new
             #submitted list of other obj keys - let's go!
             #But gotta clean up the keys in case some are 3 & some are '3'!
             #Just make them all strings?
             //pkdebug("Array is:", $arr);
             $newarr = [];
             foreach ($arr as $el) {
                 $newarr[] = "{$el}";
             }
             $addIds = array_diff($newarr, $mycurrentotherobjkeys);
             $idsToDelete = array_diff($mycurrentotherobjkeys, $newarr);
         }
         $thiskeyval = $this->getKey();
         $fresh = [];
         if ($pivotmodel) {
             if (!empty($deleteAll)) {
                 $pivotmodel::where($mykey, $thiskeyval)->delete();
             } else {
                 $pivotmodel::where($mykey, $thiskeyval)->whereIn($otherkey, $idsToDelete)->delete();
                 $fresh[$mykey] = $thiskeyval;
                 foreach ($addIds as $addId) {
                     $fresh[$otherkey] = $addId;
                     //pkdebug("Adding", $fresh);
                     $pivotmodel::create($fresh);
                 }
             }
         } else {
             if (Schema::hasTable($pivottable)) {
                 #Gotta try it with flat table
                 if (!empty($deleteAll)) {
                     DB::table($pivottable)->where($mykey, $thiskeyval)->delete();
                 } else {
                     DB::table($pivottable)->where($mykey, $thiskeyval)->whereIn($otherkey, $idsToDelete)->delete();
                     $fresh[$mykey] = $thiskeyval;
                     foreach ($addIds as $addId) {
                         $fresh[$otherkey] = $addId;
                         DB::table($pivottable)->insert($fresh);
                     }
                 }
             }
         }
     }
 }
Example #7
0
 /** Creates an HTML element or array of elements holding encoded PkModel attribute
  * data for use by JS on the page.
  * @param PkModel|arrayish PkModels - $pkmodels - the model(s) to get attributes
  * for. Can be mixed types - but then have to use the default model typename
  * @param string|null $typename - what to call the type in the element.
  *   Default is basename of the PkModel class.
  * @return HTML String|Array HTML Strings - elements in the form:
  *  <div class='encoded-data-holder' data-encoded-data-objtype="$typename"
  *   data-encoded-data-objid="$id" data-encoded-data-data="$encoded_data"></div>"
  */
 public static function jsObjDataGen($pkmodels, $typename = null)
 {
     if ($pkmodels instanceof PkModel) {
         $pkmodels = [$pkmodels];
     }
     $encodedDataHolderClass = static::$attDefaults['encodedDataHolderClass'];
     $encDatMdlDataAttr = static::$attDefaults['encDatMdlDataAttr'];
     $encDatIdDataAttr = static::$attDefaults['encDatIdDataAttr'];
     $encDatDatDataAttr = static::$attDefaults['encDatDatDataAttr'];
     //if (!$typename) $typename = strtolower(getBaseName($typeof));
     $ps = new PartialSet();
     foreach ($pkmodels as $instance) {
         if (!$instance instanceof PkModel) {
             throw new Exception("Wrong type");
         }
         if (!$typename) {
             $thistypename = strtolower(getBaseName(get_class($instance)));
         } else {
             $thistypename = $typename;
         }
         $encdata = $instance->getEncodedCustomAttributes();
         $id = $instance->id;
         $ps[] = "<div class='{$encodedDataHolderClass}' {$encDatMdlDataAttr}='{$thistypename}'\n         {$encDatIdDataAttr}='{$id}' {$encDatDatDataAttr}='{$encdata}'></div>\n";
     }
     return $ps;
 }